lsp
Use when implementing Language Server Protocol features - diagnostics, completions, hover, go-to-definition, and editor integration
When & Why to Use This Skill
This Claude skill facilitates the implementation of the Language Server Protocol (LSP), the industry standard for integrating rich language features into editors and IDEs. It provides a structured approach to building essential developer tools such as intelligent code completion, real-time diagnostics, hover information, and advanced code navigation, significantly reducing the complexity of creating language-aware development environments.
Use Cases
- Building a custom Language Server to provide syntax checking, linting, and autocomplete for proprietary or niche programming languages.
- Implementing 'Go-to-Definition' and 'Find All References' functionality in web-based or desktop code editors to improve codebase navigability.
- Developing real-time diagnostic providers that surface errors, warnings, and hints to developers as they type.
- Creating code action providers to offer automated quick-fixes and refactoring suggestions based on static analysis of the source code.
- Integrating specialized documentation tooltips and hover information to provide context-sensitive help within the editor.
| name | lsp |
|---|---|
| description | Use when implementing Language Server Protocol features - diagnostics, completions, hover, go-to-definition, and editor integration |
Language Server Protocol (LSP)
Quick Start
import { createConnection, TextDocuments, ProposedFeatures } from 'vscode-languageserver/node';
import { TextDocument } from 'vscode-languageserver-textdocument';
const connection = createConnection(ProposedFeatures.all);
const documents = new TextDocuments(TextDocument);
connection.onInitialize((params) => ({
capabilities: {
textDocumentSync: TextDocumentSyncKind.Incremental,
completionProvider: { resolveProvider: true },
hoverProvider: true,
definitionProvider: true,
diagnosticProvider: { interFileDependencies: false, workspaceDiagnostics: false }
}
}));
documents.onDidChangeContent((change) => {
validateDocument(change.document);
});
documents.listen(connection);
connection.listen();
Core Concepts
- Connection: JSON-RPC communication channel between client and server
- TextDocuments: Manages open document state with incremental sync
- Capabilities: Server declares features in
onInitializeresponse - Diagnostics: Errors/warnings pushed via
connection.sendDiagnostics()
Common Providers
| Provider | Purpose | Key Method |
|---|---|---|
completionProvider |
Autocomplete suggestions | onCompletion |
hoverProvider |
Tooltip on hover | onHover |
definitionProvider |
Go-to-definition | onDefinition |
referencesProvider |
Find all references | onReferences |
documentSymbolProvider |
Outline/symbols | onDocumentSymbol |
codeActionProvider |
Quick fixes | onCodeAction |
Key Patterns
- Use
TextDocument.positionAt(offset)andoffsetAt(position)for conversions - Return
nullfrom handlers when no result available - Diagnostics use
DiagnosticSeverity.Error | Warning | Information | Hint - Use
Locationfor definitions,LocationLinkfor richer go-to-definition