this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

gopls/protocol: rename DocumentURI.Path to DocumentURI.FilePath

The path returned from this method is GOOS-appropriate. I.e. it should
be used with the filepath package, not the path package, so its name
should reflect that.

No other changes made.

Signed-off-by: Matthew Sackman <matthew@cue.works>
Change-Id: I208783e5e3b47f7b77def41c0326160624e7aff5
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1231003
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+35 -34
+1 -1
cmd/cue/cmd/integration/workspace/workspace_folders_test.go
··· 130 130 env.DoneDiagnosingChanges(), 131 131 NoLogExactf(protocol.Debug, "Module dir=%v module=unknown Created", rootURI), 132 132 ) 133 - env.ChangeWorkspaceFolders(rootURI.Path()) 133 + env.ChangeWorkspaceFolders(rootURI.FilePath()) 134 134 env.Await( 135 135 env.DoneDiagnosingChanges(), 136 136 NoLogExactf(protocol.Debug, "Module dir=%v module=unknown Created", rootURI),
+2 -2
internal/golangorgx/gopls/cmd/cmd.go
··· 520 520 return err 521 521 } 522 522 523 - filename := mapper.URI.Path() 523 + filename := mapper.URI.FilePath() 524 524 525 525 if flags.List { 526 526 fmt.Println(filename) ··· 640 640 c.files[uri] = file 641 641 } 642 642 if file.mapper == nil { 643 - content, err := os.ReadFile(uri.Path()) 643 + content, err := os.ReadFile(uri.FilePath()) 644 644 if err != nil { 645 645 file.err = fmt.Errorf("getFile: %v: %v", uri, err) 646 646 return file
+1 -1
internal/golangorgx/gopls/cmd/span.go
··· 196 196 if c == 'f' { 197 197 uri = path.Base(uri) 198 198 } else if !fullForm { 199 - uri = s.v.URI.Path() 199 + uri = s.v.URI.FilePath() 200 200 } 201 201 fmt.Fprint(f, uri) 202 202 if !s.IsValid() || (!fullForm && s.v.Start.isZero() && s.v.End.isZero()) {
+7 -6
internal/golangorgx/gopls/protocol/uri.go
··· 67 67 return 68 68 } 69 69 70 - // Path returns the file path for the given URI. 70 + // FilePath returns the file path for the given URI. I.e. a 71 + // GOOS-appropriate path. 71 72 // 72 - // DocumentURI("").Path() returns the empty string. 73 + // DocumentURI("").FilePath() returns the empty string. 73 74 // 74 - // Path panics if called on a URI that is not a valid filename. 75 - func (uri DocumentURI) Path() string { 75 + // FilePath panics if called on a URI that is not a valid filename. 76 + func (uri DocumentURI) FilePath() string { 76 77 filename, err := filename(uri) 77 78 if err != nil { 78 79 // e.g. ParseRequestURI failed. ··· 95 96 } 96 97 // This function could be more efficiently implemented by avoiding any call 97 98 // to Path(), but at least consolidates URI manipulation. 98 - return URIFromPath(filepath.Dir(uri.Path())) 99 + return URIFromPath(filepath.Dir(uri.FilePath())) 99 100 } 100 101 101 102 // Encloses reports whether uri's path, considered as a sequence of segments, 102 103 // is a prefix of file's path. 103 104 func (uri DocumentURI) Encloses(file DocumentURI) bool { 104 - return pathutil.InDir(uri.Path(), file.Path()) 105 + return pathutil.InDir(uri.FilePath(), file.FilePath()) 105 106 } 106 107 107 108 func filename(uri DocumentURI) (string, error) {
+1 -1
internal/golangorgx/gopls/test/integration/fake/client.go
··· 140 140 case protocol.Pattern: 141 141 globPattern = pattern 142 142 case protocol.RelativePattern: 143 - globPattern = path.Join(filepath.ToSlash(pattern.BaseURI.Path()), pattern.Pattern) 143 + globPattern = path.Join(filepath.ToSlash(pattern.BaseURI.FilePath()), pattern.Pattern) 144 144 } 145 145 // TODO(rfindley): honor the watch kind. 146 146 g, err := glob.Parse(globPattern)
+3 -3
internal/golangorgx/gopls/test/integration/fake/editor.go
··· 230 230 env := make(map[string]string) 231 231 maps.Copy(env, config.Env) 232 232 for k, v := range env { 233 - v = strings.ReplaceAll(v, "$SANDBOX_WORKDIR", sandbox.Workdir.RootURI().Path()) 233 + v = strings.ReplaceAll(v, "$SANDBOX_WORKDIR", sandbox.Workdir.RootURI().FilePath()) 234 234 env[k] = v 235 235 } 236 236 ··· 257 257 // settings for the nearest folder that has customized settings, if any. 258 258 if scopeURI != nil { 259 259 var ( 260 - scopePath = protocol.DocumentURI(*scopeURI).Path() 260 + scopePath = protocol.DocumentURI(*scopeURI).FilePath() 261 261 closestDir string // longest dir with settings containing the scope, if any 262 262 closestSettings map[string]any // settings for that dir, if any 263 263 ) ··· 441 441 } 442 442 var matchedEvts []protocol.FileEvent 443 443 for _, evt := range evts { 444 - filename := filepath.ToSlash(evt.URI.Path()) 444 + filename := filepath.ToSlash(evt.URI.FilePath()) 445 445 for _, g := range e.watchPatterns { 446 446 if g.Match(filename) { 447 447 matchedEvts = append(matchedEvts, evt)
+1 -1
internal/golangorgx/gopls/test/integration/fake/workdir.go
··· 146 146 // URIToPath converts a uri to a workdir-relative path (or an absolute path, 147 147 // if the uri is outside of the workdir). 148 148 func (w *Workdir) URIToPath(uri protocol.DocumentURI) string { 149 - return w.RelPath(uri.Path()) 149 + return w.RelPath(uri.FilePath()) 150 150 } 151 151 152 152 // ReadFile reads a text file specified by a workdir-relative path.
+1 -1
internal/lsp/cache/eval.go
··· 330 330 } 331 331 } 332 332 333 - fe := e.ForFile(fileUri.Path()) 333 + fe := e.ForFile(fileUri.FilePath()) 334 334 if fe == nil { 335 335 return nil, nil, nil, nil 336 336 }
+1 -1
internal/lsp/cache/file.go
··· 38 38 // Unfortunately this is repeating work done in fscache, but due 39 39 // to import cycles, there's no way we can attach the build.File 40 40 // to the token.File (or ast.File). TODO - solve cycle somehow? 41 - bf, _ := filetypes.ParseFileAndType(uri.Path(), "", filetypes.Input) 41 + bf, _ := filetypes.ParseFileAndType(uri.FilePath(), "", filetypes.Input) 42 42 f.buildFile = bf 43 43 44 44 w.files[uri] = f
+1 -1
internal/lsp/cache/folder.go
··· 34 34 // NewWorkspaceFolder creates a new workspace folder. The name is 35 35 // entirely decorative and does not have any semantics attached to it. 36 36 func NewWorkspaceFolder(dir protocol.DocumentURI, name string) (*WorkspaceFolder, error) { 37 - dirPath := dir.Path() 37 + dirPath := dir.FilePath() 38 38 err := checkPathValid(dirPath) 39 39 if err != nil { 40 40 return nil, fmt.Errorf("invalid workspace folder path %v: %w; check that the spelling of the configured workspace folder path agrees with the spelling reported by the operating system", dirPath, err)
+3 -3
internal/lsp/cache/module.go
··· 133 133 m.delete() 134 134 return ErrBadModule 135 135 } 136 - modFile, err := modfile.ParseNonStrict(fh.Content(), m.modFileURI.Path()) 136 + modFile, err := modfile.ParseNonStrict(fh.Content(), m.modFileURI.FilePath()) 137 137 if err != nil { 138 138 w.debugLogf("%v Error when reloading: %v", m, err) 139 139 m.delete() ··· 337 337 reqs := modrequirements.NewRequirements(modPath, w.registry, m.modFile.DepVersions(), m.modFile.DefaultMajorVersions()) 338 338 ctx := context.Background() 339 339 loc := module.SourceLoc{ 340 - FS: w.overlayFS.IoFS(m.rootURI.Path()), 340 + FS: w.overlayFS.IoFS(m.rootURI.FilePath()), 341 341 Dir: ".", // NB can't be "" 342 342 } 343 343 // Determinism in log messages: ··· 366 366 activeFiles, _ := m.workspace.activeFilesAndDirs() 367 367 368 368 var toLoad []protocol.DocumentURI 369 - rootPath := m.rootURI.Path() 369 + rootPath := m.rootURI.FilePath() 370 370 fsys := m.workspace.overlayFS.IoFS(rootPath) 371 371 fs.WalkDir(fsys, ".", func(p string, d fs.DirEntry, err error) error { 372 372 if err != nil {
+1 -1
internal/lsp/cache/package.go
··· 375 375 if embeddings == nil { 376 376 embeddings = make(map[token.Pos]*embedding) 377 377 } 378 - fs := w.overlayFS.IoFS(m.rootURI.Path()) 378 + fs := w.overlayFS.IoFS(m.rootURI.FilePath()) 379 379 for _, embed := range embeddedPaths { 380 380 embedding := &embedding{Embed: embed} 381 381 embeddings[embed.Attribute.Pos] = embedding
+3 -3
internal/lsp/cache/workspace.go
··· 98 98 // idempotent: if the workspace already includes a workspace folder at 99 99 // dir, then this method is a noop and returns nil. 100 100 func (w *Workspace) EnsureFolder(dir protocol.DocumentURI, name string) (*WorkspaceFolder, error) { 101 - inode1, err := os.Stat(dir.Path()) 101 + inode1, err := os.Stat(dir.FilePath()) 102 102 if err != nil { 103 103 return nil, err 104 104 } ··· 106 106 if wf.dir == dir { 107 107 return wf, nil 108 108 } 109 - inode2, err := os.Stat(filepath.FromSlash(wf.dir.Path())) 109 + inode2, err := os.Stat(filepath.FromSlash(wf.dir.FilePath())) 110 110 if err != nil { 111 111 return nil, err 112 112 } ··· 224 224 for _, wfDir := range wfDirs { 225 225 // NB: a.Encloses(b) returns true if a == b 226 226 if wfDir.Encloses(activeDir) { 227 - patterns[protocol.RelativePattern{Pattern: filepath.ToSlash(activeDir.Path())}] = struct{}{} 227 + patterns[protocol.RelativePattern{Pattern: filepath.ToSlash(activeDir.FilePath())}] = struct{}{} 228 228 break 229 229 } 230 230 }
+2 -2
internal/lsp/fscache/fs_cache.go
··· 261 261 // [iofs.ErrNotExist]. If uri is a directory, the error will be 262 262 // [iofs.PathError]. 263 263 func (fs *CUECacheFS) ReadFile(uri protocol.DocumentURI) (FileHandle, error) { 264 - id, mtime, err := robustio.GetFileID(uri.Path()) 264 + id, mtime, err := robustio.GetFileID(uri.FilePath()) 265 265 if err != nil { 266 266 if errors.Is(err, iofs.ErrNotExist) { 267 267 // URI could have been a file, or a directory. In both cases ··· 350 350 351 351 func readFile(uri protocol.DocumentURI, mtime time.Time) (*diskFileEntry, error) { 352 352 // NB filePath is GOOS-appropriate (uri.Path() calls [filepath.FromSlash]) 353 - filePath := uri.Path() 353 + filePath := uri.FilePath() 354 354 355 355 bf, err := filetypes.ParseFileAndType(filePath, "", filetypes.Input) 356 356 if err != nil {
+3 -3
internal/lsp/fscache/fs_overlay.go
··· 225 225 if !strings.HasPrefix(string(uri), fileSchemePrefix) { 226 226 panic(fmt.Sprintf("%q is not a valid DocumentURI", uri)) 227 227 } 228 - str := filepath.Clean(uri.Path()) 228 + str := filepath.Clean(uri.FilePath()) 229 229 if str == "." { // if uri.Path() returns "", filepath.Clean() returns "." 230 230 return nil, "" 231 231 } ··· 334 334 335 335 file, isFile := entry.(*overlayFileEntry) 336 336 if !isFile { 337 - return nil, &iofs.PathError{Op: "ReadFile", Path: uri.Path(), Err: iofs.ErrInvalid} 337 + return nil, &iofs.PathError{Op: "ReadFile", Path: uri.FilePath(), Err: iofs.ErrInvalid} 338 338 } 339 339 340 340 return file, nil ··· 473 473 // This modifies the overlay *only*. It does not, under any 474 474 // circumstances, access the underlying CUECacheFS. 475 475 func (txn *UpdateTxn) Set(uri protocol.DocumentURI, content []byte, mtime time.Time, version int32) (FileHandle, error) { 476 - filePath := uri.Path() 476 + filePath := uri.FilePath() 477 477 components, entryName := txn.pathComponents(uri) 478 478 dir, err := txn.getDirLocked(components, true) 479 479 if err != nil {
+1 -1
internal/lsp/server/initialize.go
··· 77 77 if len(folders) == 0 && params.RootURI != "" { 78 78 folders = []protocol.WorkspaceFolder{{ 79 79 URI: string(params.RootURI), 80 - Name: path.Base(params.RootURI.Path()), 80 + Name: path.Base(params.RootURI.FilePath()), 81 81 }} 82 82 } 83 83
+1 -1
internal/lsp/server/watching.go
··· 76 76 } else { 77 77 p := pattern.Pattern 78 78 if pattern.BaseURI != "" { 79 - p = path.Join(filepath.ToSlash(pattern.BaseURI.Path()), p) 79 + p = path.Join(filepath.ToSlash(pattern.BaseURI.FilePath()), p) 80 80 } 81 81 value = p 82 82 }