Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mcy committed Oct 10, 2024
1 parent 42ee60a commit 95da30a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions private/buf/buflsp/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ func (f *file) IndexImports(ctx context.Context) {
// Thus, we search for name and all of its path suffixes. This is not
// ideal but is our only option in this case.
var fileInfo storage.ObjectInfo
var pathWasTruncated bool
name := node.Name.AsString()
for {
fileInfo, ok = importable[name]
Expand All @@ -342,11 +343,21 @@ func (f *file) IndexImports(ctx context.Context) {
}

name = name[idx+1:]
pathWasTruncated = true
}
if fileInfo == nil {
f.lsp.logger.Warn(fmt.Sprintf("could not find URI for import %q", node.Name.AsString()))
continue
}
if pathWasTruncated && !strings.HasSuffix(fileInfo.LocalPath(), node.Name.AsString()) {
// Verify that the file we found, with a potentially too-short path, does in fact have
// the "correct" full path as a prefix. E.g., suppose we import a/b/c.proto. We find
// c.proto in importable. Now, we look at the full local path, which we expect to be of
// the form /home/blah/.cache/blah/a/b/c.proto or similar. If it does not contain
// a/b/c.proto as a suffix, we didn't find our file.
f.lsp.logger.Warn(fmt.Sprintf("could not find URI for import %q, but found same-suffix path %q", node.Name.AsString(), fileInfo.LocalPath()))
continue
}

f.lsp.logger.Debug(
"mapped import -> path",
Expand Down

0 comments on commit 95da30a

Please sign in to comment.