Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

- Fix LSP go-to-definition, references, hover, and rename for file options.
- Fix an LSP crash when organizing imports in a workspace with a file that fails to build.
- Fix the `PROTOVALIDATE` lint rule to check constant arguments to `duration`, `timestamp`, and
`matches` in CEL expressions, such as `duration('1d')` or an invalid regex, which otherwise only
Expand Down
25 changes: 25 additions & 0 deletions private/buf/buflsp/definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,31 @@ func TestDefinition(t *testing.T) {
}
}

func TestDefinitionFileOption(t *testing.T) {
t.Parallel()

ctx := t.Context()

testProtoPath, err := filepath.Abs("testdata/definition/file_options.proto")
require.NoError(t, err)
optionsProtoPath, err := filepath.Abs("testdata/definition/options.proto")
require.NoError(t, err)

clientJSONConn, testURI := setupLSPServer(t, testProtoPath)

var locations []protocol.Location
_, err = clientJSONConn.Call(ctx, protocol.MethodTextDocumentDefinition, protocol.DefinitionParams{
TextDocumentPositionParams: protocol.TextDocumentPositionParams{
TextDocument: protocol.TextDocumentIdentifier{URI: testURI},
Position: protocol.Position{Line: 6, Character: 22},
},
}, &locations)
require.NoError(t, err)
require.Len(t, locations, 1)
assert.Equal(t, buflsp.FilePathToURI(optionsProtoPath), locations[0].URI)
assert.Equal(t, protocol.Position{Line: 7, Character: 9}, locations[0].Range.Start)
}

// TestDefinitionURLEncoding verifies that file paths with special characters
// like '@' are properly URL-encoded in the URI responses.
func TestDefinitionURLEncoding(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions private/buf/buflsp/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ func (f *file) indexSymbols() ([]*symbol, []*symbol) {
resolved = append(resolved, resolvedSyms...)
unresolved = append(unresolved, unresolvedSyms...)
}
unresolved = append(unresolved, f.messageToSymbols(f.ir.Options())...)
return resolved, unresolved
}

Expand Down
29 changes: 29 additions & 0 deletions private/buf/buflsp/references_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,35 @@ func TestReferencesStableAcrossReindex(t *testing.T) {
assert.Len(t, slices.Compact(slices.Clone(after)), len(after), "re-indexing introduced duplicate references")
}

func TestReferencesFileOption(t *testing.T) {
t.Parallel()

ctx := t.Context()

fileOptionsProtoPath, err := filepath.Abs("testdata/definition/file_options.proto")
require.NoError(t, err)
optionsProtoPath, err := filepath.Abs("testdata/definition/options.proto")
require.NoError(t, err)

clientJSONConn, fileOptionsURI := setupLSPServer(t, fileOptionsProtoPath)
optionsURI := buflsp.FilePathToURI(optionsProtoPath)

locations := testRequestReferences(ctx, t, clientJSONConn, optionsURI, 7, 10, true)

type refLocation struct {
uri uri.URI
line uint32
}
var actual []refLocation
for _, location := range locations {
actual = append(actual, refLocation{uri: location.URI, line: location.Range.Start.Line})
}
assert.ElementsMatch(t, []refLocation{
{uri: optionsURI, line: 7},
{uri: fileOptionsURI, line: 6},
}, actual)
}

// testRequestReferences sends a textDocument/references request and returns the locations.
func testRequestReferences(
ctx context.Context,
Expand Down
7 changes: 7 additions & 0 deletions private/buf/buflsp/testdata/definition/file_options.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";

package definition.v1;

import "options.proto";

option (definition.v1.file_tag) = "f";
9 changes: 9 additions & 0 deletions private/buf/buflsp/testdata/definition/options.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
syntax = "proto3";

package definition.v1;

import "google/protobuf/descriptor.proto";

extend google.protobuf.FileOptions {
string file_tag = 50001;
}
Loading