Skip to content

Commit 3de973b

Browse files
committed
feat: add Go LSP configuration and code navigation documentation
Change-Id: I994c8ee8fa2c246808a9f68a86e83a6a3db6f8ac Signed-off-by: Thomas Kosiewski <tk@coder.com>
1 parent abbe929 commit 3de973b

File tree

3 files changed

+136
-0
lines changed

3 files changed

+136
-0
lines changed

.claude/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"permissions": {
3+
"allow": [],
4+
"deny": [
5+
"mcp__go-language-server__edit_file"
6+
]
7+
}
8+
}

.mcp.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"mcpServers": {
3+
"go-language-server": {
4+
"type": "stdio",
5+
"command": "go",
6+
"args": [
7+
"run",
8+
"github.com/isaacphi/mcp-language-server@latest",
9+
"-workspace",
10+
"./",
11+
"-lsp",
12+
"go",
13+
"--",
14+
"run",
15+
"golang.org/x/tools/gopls@latest"
16+
],
17+
"env": {}
18+
}
19+
}
20+
}

CLAUDE.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,114 @@ if errors.Is(err, errInvalidPKCE) {
270270
- Test both positive and negative cases
271271
- Use `testutil.WaitLong` for timeouts in tests
272272

273+
## Code Navigation and Investigation
274+
275+
### Using Go LSP Tools (STRONGLY RECOMMENDED)
276+
277+
**IMPORTANT**: Always use Go LSP tools for code navigation and understanding. These tools provide accurate, real-time analysis of the codebase and should be your first choice for code investigation.
278+
279+
When working with the Coder codebase, leverage Go Language Server Protocol tools for efficient code navigation:
280+
281+
1. **Find function definitions** (USE THIS FREQUENTLY):
282+
283+
```none
284+
mcp__go-language-server__definition symbolName
285+
```
286+
287+
- Example: `mcp__go-language-server__definition getOAuth2ProviderAppAuthorize`
288+
- Example: `mcp__go-language-server__definition ExtractAPIKeyMW`
289+
- Quickly jump to function implementations across packages
290+
- **Use this when**: You see a function call and want to understand its implementation
291+
- **Tip**: Include package prefix if symbol is ambiguous (e.g., `httpmw.ExtractAPIKeyMW`)
292+
293+
2. **Find symbol references** (ESSENTIAL FOR UNDERSTANDING IMPACT):
294+
295+
```none
296+
mcp__go-language-server__references symbolName
297+
```
298+
299+
- Example: `mcp__go-language-server__references APITokenFromRequest`
300+
- Locate all usages of functions, types, or variables
301+
- Understand code dependencies and call patterns
302+
- **Use this when**: Making changes to understand what code might be affected
303+
- **Critical for**: Refactoring, deprecating functions, or understanding data flow
304+
305+
3. **Get symbol information** (HELPFUL FOR TYPE INFO):
306+
307+
```none
308+
mcp__go-language-server__hover filePath line column
309+
```
310+
311+
- Example: `mcp__go-language-server__hover /Users/thomask33/Projects/coder/coderd/httpmw/apikey.go 560 25`
312+
- Get type information and documentation at specific positions
313+
- **Use this when**: You need to understand the type of a variable or return value
314+
315+
4. **Edit files using LSP** (WHEN MAKING TARGETED CHANGES):
316+
317+
```none
318+
mcp__go-language-server__edit_file filePath edits
319+
```
320+
321+
- Make precise edits using line numbers
322+
- **Use this when**: You need to make small, targeted changes to specific lines
323+
324+
5. **Get diagnostics** (ALWAYS CHECK AFTER CHANGES):
325+
326+
```none
327+
mcp__go-language-server__diagnostics filePath
328+
```
329+
330+
- Check for compilation errors, unused imports, etc.
331+
- **Use this when**: After making changes to ensure code is still valid
332+
333+
### LSP Tool Usage Priority
334+
335+
**ALWAYS USE THESE TOOLS FIRST**:
336+
337+
- **Use LSP `definition`** instead of manual searching for function implementations
338+
- **Use LSP `references`** instead of grep when looking for function/type usage
339+
- **Use LSP `hover`** to understand types and signatures
340+
- **Use LSP `diagnostics`** after making changes to check for errors
341+
342+
**When to use other tools**:
343+
344+
- **Use Grep for**: Text-based searches, finding patterns across files, searching comments
345+
- **Use Bash for**: Running tests, git commands, build operations
346+
- **Use Read tool for**: Reading configuration files, documentation, non-Go files
347+
348+
### Investigation Strategy (LSP-First Approach)
349+
350+
1. **Start with route registration** in `coderd/coderd.go` to understand API endpoints
351+
2. **Use LSP `definition` lookup** to trace from route handlers to actual implementations
352+
3. **Use LSP `references`** to understand how functions are called throughout the codebase
353+
4. **Follow the middleware chain** using LSP tools to understand request processing flow
354+
5. **Check test files** for expected behavior and error patterns
355+
6. **Use LSP `diagnostics`** to ensure your changes don't break compilation
356+
357+
### Common LSP Workflows
358+
359+
**Understanding a new feature**:
360+
361+
1. Use `grep` to find the main entry point (e.g., route registration)
362+
2. Use LSP `definition` to jump to handler implementation
363+
3. Use LSP `references` to see how the handler is used
364+
4. Use LSP `definition` on each function call within the handler
365+
366+
**Making changes to existing code**:
367+
368+
1. Use LSP `references` to understand the impact of your changes
369+
2. Use LSP `definition` to understand the current implementation
370+
3. Make your changes using `Edit` or LSP `edit_file`
371+
4. Use LSP `diagnostics` to verify your changes compile correctly
372+
5. Run tests to ensure functionality still works
373+
374+
**Debugging issues**:
375+
376+
1. Use LSP `definition` to find the problematic function
377+
2. Use LSP `references` to trace how the function is called
378+
3. Use LSP `hover` to understand parameter types and return values
379+
4. Use `Read` to examine the full context around the issue
380+
273381
## Testing Scripts
274382
275383
### OAuth2 Test Scripts

0 commit comments

Comments
 (0)