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
6 changes: 6 additions & 0 deletions demo-output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,12 @@
lineNumber: 1
variables:
file: file:///examples/nodejs/Component.tsx
- uri: file:///examples/nodejs/Component.tsx
message: Found React reference using nodejs provider
codeSnip: " 1 import React from 'react';\n 2 \n 3 export const MyComponent: React.FC = () => {\n 4 return <div>Hello from TypeScript React</div>;\n 5 };\n"
lineNumber: 3
variables:
file: file:///examples/nodejs/Component.tsx
- uri: file:///examples/nodejs/LegacyComponent.jsx
message: Found React reference using nodejs provider
codeSnip: " 1 import React from 'react';\n 2 \n 3 export const LegacyComponent = () => {\n 4 return <div>Hello from JavaScript React</div>;\n 5 };\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"path/filepath"
"strings"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -45,7 +46,11 @@ func (n *NodeServiceClientBuilder) Init(ctx context.Context, log logr.Logger, c

params := protocol.InitializeParams{}

// treat location as the only workspace folder
if c.Location != "" {
if !strings.HasPrefix(c.Location, "file://") {
c.Location = "file://" + c.Location
}
sc.Config.WorkspaceFolders = []string{c.Location}
}

Expand All @@ -59,16 +64,45 @@ func (n *NodeServiceClientBuilder) Init(ctx context.Context, log logr.Logger, c
} else {
params.RootURI = sc.Config.WorkspaceFolders[0]
}
// var workspaceFolders []protocol.WorkspaceFolder
// for _, f := range sc.Config.WorkspaceFolders {
// workspaceFolders = append(workspaceFolders, protocol.WorkspaceFolder{
// URI: f,
// Name: f,
// })
// }
// params.WorkspaceFolders = workspaceFolders

params.Capabilities = protocol.ClientCapabilities{}
var workspaceFolders []protocol.WorkspaceFolder
seen := make(map[string]bool)
for _, f := range sc.Config.WorkspaceFolders {
if seen[f] {
continue
}
seen[f] = true
workspaceFolders = append(workspaceFolders, protocol.WorkspaceFolder{
URI: f,
Name: filepath.Base(strings.ReplaceAll(f, "file://", "")),
})
}
params.WorkspaceFolders = workspaceFolders

params.Capabilities = protocol.ClientCapabilities{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either here or a follow up can note what each of these does and why we need them?

Workspace: &protocol.WorkspaceClientCapabilities{
WorkspaceFolders: true,
// enables the server to refresh diagnostics on-demand, useful in agent mode
Diagnostics: &protocol.DiagnosticWorkspaceClientCapabilities{
RefreshSupport: true,
},
},
TextDocument: &protocol.TextDocumentClientCapabilities{
// this enables the textDocument/definition responses to be
// LocationLink[] instead of Location[]. LocationLink contains
// source -> target mapping of symbols which gives us more information
Definition: &protocol.DefinitionClientCapabilities{
LinkSupport: true,
},
// this enables the documentSymbol responses to be a tree instead of a flat list
// this allows us to understand enclosed symbols better. Right now, we use this
// information to find a concrete symbol at a location. While a flat list could
// work, but in future, the tree will help us with advanced queries.
DocumentSymbol: &protocol.DocumentSymbolClientCapabilities{
HierarchicalDocumentSymbolSupport: true,
},
},
}

var InitializationOptions map[string]any
err = json.Unmarshal([]byte(sc.Config.LspServerInitializationOptions), &InitializationOptions)
Expand Down Expand Up @@ -140,7 +174,7 @@ func (sc *NodeServiceClient) EvaluateReferenced(ctx context.Context, cap string,
}

// Query symbols once after all files are indexed
symbols := sc.GetAllDeclarations(ctx, query)
symbols := sc.GetAllDeclarations(ctx, query, false)
incidentsMap, err := sc.EvaluateSymbols(ctx, symbols)
if err != nil {
return resp{}, err
Expand Down
2 changes: 1 addition & 1 deletion lsp/base_service_client/base_capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func EvaluateReferenced[T base](t T, ctx ctx, cap string, info []byte) (resp, er
return resp{}, fmt.Errorf("unable to get query info")
}

symbols := sc.GetAllDeclarations(ctx, query)
symbols := sc.GetAllDeclarations(ctx, query, true)

incidents := []provider.IncidentContext{}
incidentsMap := make(map[string]provider.IncidentContext) // Remove duplicates
Expand Down
Loading
Loading