-
Notifications
You must be signed in to change notification settings - Fork 103
Add support for hover, rename, document symbols. Compacted scoping for references and cleaner formatting. #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
05ed0ff
Add support for hover, rename, document symbols. Compacted scoping fo…
orsenkucher 7715dbc
fixed scopes and reference context
orsenkucher c53c881
Refactorings
orsenkucher 1177255
Fixes for references, HierarchicalDocumentSymbolSupport, mcp client f…
orsenkucher 7d71a9a
Improved client cli commands
orsenkucher 8c944cc
Add delay to debug mcp client and allow to change projects
orsenkucher d2562cf
Read Definition tool done
orsenkucher ab399c3
Test hover in rust project
orsenkucher 997ef38
delete not working script
orsenkucher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,9 @@ mcp-language-server | |
|
|
||
| # Temporary files | ||
| *~ | ||
|
|
||
| # MCP Server config | ||
| .mcp.json | ||
|
|
||
| # Markdown files with notes | ||
| notes | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "mcpServers": { | ||
| "language-server": { | ||
| "type": "stdio", | ||
| "command": "/Users/orsen/Develop/mcp-language-server/mcp-language-server", | ||
| "args": [ | ||
| "--workspace", | ||
| "/Users/orsen/Develop/mcp-language-server", | ||
| "--lsp", | ||
| "gopls" | ||
| ], | ||
| "env": {} | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| package tools | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/isaacphi/mcp-language-server/internal/lsp" | ||
| "github.com/isaacphi/mcp-language-server/internal/protocol" | ||
| "github.com/isaacphi/mcp-language-server/internal/utilities" | ||
| ) | ||
|
|
||
| // GetDocumentSymbols retrieves all symbols in a document and formats them in a hierarchical structure | ||
| func GetDocumentSymbols(ctx context.Context, client *lsp.Client, filePath string, showLineNumbers bool) (string, error) { | ||
| // Open the file if not already open | ||
| err := client.OpenFile(ctx, filePath) | ||
| if err != nil { | ||
| return "", fmt.Errorf("could not open file: %v", err) | ||
| } | ||
|
|
||
| // Convert to URI format for LSP protocol | ||
| uri := protocol.DocumentUri("file://" + filePath) | ||
|
|
||
| // Create the document symbol parameters | ||
| symParams := protocol.DocumentSymbolParams{ | ||
| TextDocument: protocol.TextDocumentIdentifier{ | ||
| URI: uri, | ||
| }, | ||
| } | ||
|
|
||
| // Execute the document symbol request | ||
| symResult, err := client.DocumentSymbol(ctx, symParams) | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to get document symbols: %v", err) | ||
| } | ||
|
|
||
| symbols, err := symResult.Results() | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to process document symbols: %v", err) | ||
| } | ||
|
|
||
| if len(symbols) == 0 { | ||
| return fmt.Sprintf("No symbols found in %s", filePath), nil | ||
| } | ||
|
|
||
| var result strings.Builder | ||
| result.WriteString(fmt.Sprintf("Symbols in %s\n\n", filePath)) | ||
|
|
||
| // Format symbols hierarchically | ||
| formatSymbols(&result, symbols, 0, showLineNumbers) | ||
|
|
||
| return result.String(), nil | ||
| } | ||
|
|
||
| // formatSymbols recursively formats symbols with proper indentation | ||
| func formatSymbols(sb *strings.Builder, symbols []protocol.DocumentSymbolResult, level int, showLineNumbers bool) { | ||
| indent := strings.Repeat(" ", level) | ||
|
|
||
| for _, sym := range symbols { | ||
| // Get symbol information | ||
| name := sym.GetName() | ||
|
|
||
| // Format location information | ||
| location := "" | ||
| if showLineNumbers { | ||
| r := sym.GetRange() | ||
| if r.Start.Line == r.End.Line { | ||
| location = fmt.Sprintf("Line %d", r.Start.Line+1) | ||
| } else { | ||
| location = fmt.Sprintf("Lines %d-%d", r.Start.Line+1, r.End.Line+1) | ||
| } | ||
| } | ||
|
|
||
| // Use the shared utility to extract kind information | ||
| kindStr := utilities.ExtractSymbolKind(sym) | ||
|
|
||
| // Format the symbol entry | ||
| if location != "" { | ||
| sb.WriteString(fmt.Sprintf("%s%s %s (%s)\n", indent, kindStr, name, location)) | ||
| } else { | ||
| sb.WriteString(fmt.Sprintf("%s%s %s\n", indent, kindStr, name)) | ||
| } | ||
|
|
||
| // Format children if it's a DocumentSymbol | ||
| if ds, ok := sym.(*protocol.DocumentSymbol); ok && len(ds.Children) > 0 { | ||
| childSymbols := make([]protocol.DocumentSymbolResult, len(ds.Children)) | ||
| for i := range ds.Children { | ||
| childSymbols[i] = &ds.Children[i] | ||
| } | ||
| formatSymbols(sb, childSymbols, level+1, showLineNumbers) | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.