diff --git a/pkg/lsp/refactor.go b/pkg/lsp/refactor.go index 67977f9..cb293a4 100644 --- a/pkg/lsp/refactor.go +++ b/pkg/lsp/refactor.go @@ -434,6 +434,8 @@ func newFieldVisitor(tracker *paths.AncestorTracker, paths *[]protopath.Values) switch node.(type) { case *ast.MessageNode, *ast.GroupNode, *ast.FieldNode, *ast.MapFieldNode: return visitEnclosingRange(tracker, paths) + case *ast.FileNode: + return true } return false } @@ -480,7 +482,7 @@ func extractFields(ctx context.Context, request *protocol.CodeActionParams, link continue } if parentNodePath.Len() == 0 { - parentNodePath = paths.Slice(path, 0, parentNodePath.Len()-1) + parentNodePath = paths.Slice(path, 0, path.Len()-1) } else if !parentNodePath.Index(-1).Value.Equal(path.Index(-1).Value) { return // fields in the range must share the same parent } diff --git a/pkg/lsp/search.go b/pkg/lsp/search.go index f48f277..33fcb4d 100644 --- a/pkg/lsp/search.go +++ b/pkg/lsp/search.go @@ -799,6 +799,8 @@ func visitEnclosingRange(tracker *paths.AncestorTracker, paths *[]protopath.Valu func DefaultEnclosingRangeVisitor(tracker *paths.AncestorTracker, paths *[]protopath.Values) func(ast.Node) bool { return func(node ast.Node) bool { switch node.(type) { + case *ast.FileNode: + return true case *ast.ImportNode, *ast.SyntaxNode, *ast.MessageNode, diff --git a/pkg/lsp/symbols.go b/pkg/lsp/symbols.go index f8cd6a2..8fb6d5c 100644 --- a/pkg/lsp/symbols.go +++ b/pkg/lsp/symbols.go @@ -28,6 +28,10 @@ func (c *Cache) documentSymbolsForFileLocked(uri protocol.DocumentURI) ([]protoc var symbols []protocol.DocumentSymbol fn := f.AST() + if fn == nil { + return nil, nil + } + for _, decl := range fn.Decls { switch node := decl.Unwrap().(type) { case *ast.MessageNode: