X-Git-Url: https://git.josue.xyz/?a=blobdiff_plain;f=.config%2Fcoc%2Fextensions%2Fcoc-go-data%2Ftools%2Fpkg%2Fmod%2Fgolang.org%2Fx%2Ftools%40v0.1.0%2Fgodoc%2Fvfs%2Fos.go;fp=.config%2Fcoc%2Fextensions%2Fcoc-go-data%2Ftools%2Fpkg%2Fmod%2Fgolang.org%2Fx%2Ftools%40v0.1.0%2Fgodoc%2Fvfs%2Fos.go;h=35d050946e66e8a79b5da4cdb944ebf7fb3fa609;hb=3c06164f15bd10aed7d66b6314764a2961a14762;hp=0000000000000000000000000000000000000000;hpb=0e9c3ceb40901f4d44981c1376cb9e23a248e006;p=dotfiles%2F.git diff --git a/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.1.0/godoc/vfs/os.go b/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.1.0/godoc/vfs/os.go new file mode 100644 index 00000000..35d05094 --- /dev/null +++ b/.config/coc/extensions/coc-go-data/tools/pkg/mod/golang.org/x/tools@v0.1.0/godoc/vfs/os.go @@ -0,0 +1,105 @@ +// Copyright 2013 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package vfs + +import ( + "fmt" + "go/build" + "io/ioutil" + "os" + pathpkg "path" + "path/filepath" + "runtime" +) + +// We expose a new variable because otherwise we need to copy the findGOROOT logic again +// from cmd/godoc which is already copied twice from the standard library. + +// GOROOT is the GOROOT path under which the godoc binary is running. +// It is needed to check whether a filesystem root is under GOROOT or not. +// This is set from cmd/godoc/main.go. +var GOROOT = runtime.GOROOT() + +// OS returns an implementation of FileSystem reading from the +// tree rooted at root. Recording a root is convenient everywhere +// but necessary on Windows, because the slash-separated path +// passed to Open has no way to specify a drive letter. Using a root +// lets code refer to OS(`c:\`), OS(`d:\`) and so on. +func OS(root string) FileSystem { + var t RootType + switch { + case root == GOROOT: + t = RootTypeGoRoot + case isGoPath(root): + t = RootTypeGoPath + } + return osFS{rootPath: root, rootType: t} +} + +type osFS struct { + rootPath string + rootType RootType +} + +func isGoPath(path string) bool { + for _, bp := range filepath.SplitList(build.Default.GOPATH) { + for _, gp := range filepath.SplitList(path) { + if bp == gp { + return true + } + } + } + return false +} + +func (root osFS) String() string { return "os(" + root.rootPath + ")" } + +// RootType returns the root type for the filesystem. +// +// Note that we ignore the path argument because roottype is a property of +// this filesystem. But for other filesystems, the roottype might need to be +// dynamically deduced at call time. +func (root osFS) RootType(path string) RootType { + return root.rootType +} + +func (root osFS) resolve(path string) string { + // Clean the path so that it cannot possibly begin with ../. + // If it did, the result of filepath.Join would be outside the + // tree rooted at root. We probably won't ever see a path + // with .. in it, but be safe anyway. + path = pathpkg.Clean("/" + path) + + return filepath.Join(root.rootPath, path) +} + +func (root osFS) Open(path string) (ReadSeekCloser, error) { + f, err := os.Open(root.resolve(path)) + if err != nil { + return nil, err + } + fi, err := f.Stat() + if err != nil { + f.Close() + return nil, err + } + if fi.IsDir() { + f.Close() + return nil, fmt.Errorf("Open: %s is a directory", path) + } + return f, nil +} + +func (root osFS) Lstat(path string) (os.FileInfo, error) { + return os.Lstat(root.resolve(path)) +} + +func (root osFS) Stat(path string) (os.FileInfo, error) { + return os.Stat(root.resolve(path)) +} + +func (root osFS) ReadDir(path string) ([]os.FileInfo, error) { + return ioutil.ReadDir(root.resolve(path)) // is sorted +}