From c007d5334dc135b048d0bc05f0deb80e8c37d1b0 Mon Sep 17 00:00:00 2001 From: Claude Assistant Date: Thu, 26 Jun 2025 00:37:06 +0100 Subject: [PATCH] Add initialize_params.json for C# language server MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Creates consistent initialization structure with other language servers: - Extracts hardcoded initialization parameters to JSON configuration - Uses template variables ($rootPath, $rootUri, $rootName) for dynamic values - Maintains all existing capabilities and functionality - Follows the established pattern used by 10/12 other language servers This improves maintainability by allowing initialization parameter modifications without code changes and ensures consistency across all language server implementations. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../csharp_language_server.py | 121 +++------------ .../initialize_params.json | 141 ++++++++++++++++++ 2 files changed, 162 insertions(+), 100 deletions(-) create mode 100644 src/solidlsp/language_servers/csharp_language_server/initialize_params.json diff --git a/src/solidlsp/language_servers/csharp_language_server/csharp_language_server.py b/src/solidlsp/language_servers/csharp_language_server/csharp_language_server.py index 5b65e398..5ba8dd17 100644 --- a/src/solidlsp/language_servers/csharp_language_server/csharp_language_server.py +++ b/src/solidlsp/language_servers/csharp_language_server/csharp_language_server.py @@ -399,106 +399,27 @@ class CSharpLanguageServer(SolidLanguageServer): """ Returns the initialize params for the Microsoft.CodeAnalysis.LanguageServer. """ - initialize_params: InitializeParams = { # type: ignore - "processId": os.getpid(), - "rootPath": repository_absolute_path, - "rootUri": pathlib.Path(repository_absolute_path).as_uri(), - "capabilities": { - "window": { - "workDoneProgress": True, - "showMessage": {"messageActionItem": {"additionalPropertiesSupport": True}}, - "showDocument": {"support": True} - }, - "workspace": { - "applyEdit": True, - "workspaceEdit": {"documentChanges": True}, - "didChangeConfiguration": {"dynamicRegistration": True}, - "didChangeWatchedFiles": {"dynamicRegistration": True}, - "symbol": { - "dynamicRegistration": True, - "symbolKind": { - "valueSet": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26] - }, - }, - "executeCommand": {"dynamicRegistration": True}, - "configuration": True, - "workspaceFolders": True, - "workDoneProgress": True, - }, - "textDocument": { - "synchronization": { - "dynamicRegistration": True, - "willSave": True, - "willSaveWaitUntil": True, - "didSave": True - }, - "completion": { - "dynamicRegistration": True, - "contextSupport": True, - "completionItem": { - "snippetSupport": True, - "commitCharactersSupport": True, - "documentationFormat": ["markdown", "plaintext"], - "deprecatedSupport": True, - "preselectSupport": True, - }, - "completionItemKind": { - "valueSet": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25] - }, - }, - "hover": {"dynamicRegistration": True, "contentFormat": ["markdown", "plaintext"]}, - "signatureHelp": { - "dynamicRegistration": True, - "signatureInformation": { - "documentationFormat": ["markdown", "plaintext"], - "parameterInformation": {"labelOffsetSupport": True}, - }, - }, - "definition": {"dynamicRegistration": True}, - "references": {"dynamicRegistration": True}, - "documentHighlight": {"dynamicRegistration": True}, - "documentSymbol": { - "dynamicRegistration": True, - "symbolKind": { - "valueSet": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26] - }, - "hierarchicalDocumentSymbolSupport": True, - }, - "codeAction": { - "dynamicRegistration": True, - "codeActionLiteralSupport": { - "codeActionKind": { - "valueSet": [ - "", - "quickfix", - "refactor", - "refactor.extract", - "refactor.inline", - "refactor.rewrite", - "source", - "source.organizeImports", - ] - } - }, - }, - "codeLens": {"dynamicRegistration": True}, - "formatting": {"dynamicRegistration": True}, - "rangeFormatting": {"dynamicRegistration": True}, - "onTypeFormatting": {"dynamicRegistration": True}, - "rename": {"dynamicRegistration": True}, - "publishDiagnostics": {"relatedInformation": True}, - "foldingRange": { - "dynamicRegistration": True, - "rangeLimit": 5000, - "lineFoldingOnly": True - }, - }, - }, - "workspaceFolders": [ - {"uri": pathlib.Path(repository_absolute_path).as_uri(), "name": os.path.basename(repository_absolute_path)} - ], - } - + import json + + # Load initialization parameters from JSON file + with open(os.path.join(os.path.dirname(__file__), "initialize_params.json"), encoding="utf-8") as f: + initialize_params_template = json.load(f) + + # Convert the template string to actual values + initialize_params_str = json.dumps(initialize_params_template) + + # Replace template variables + root_uri = pathlib.Path(repository_absolute_path).as_uri() + root_name = os.path.basename(repository_absolute_path) + + initialize_params_str = initialize_params_str.replace("$rootPath", repository_absolute_path) + initialize_params_str = initialize_params_str.replace("$rootUri", root_uri) + initialize_params_str = initialize_params_str.replace("$rootName", root_name) + initialize_params_str = initialize_params_str.replace('"os.getpid()"', str(os.getpid())) + + # Parse back to dictionary + initialize_params = json.loads(initialize_params_str) + return initialize_params def _start_server(self): diff --git a/src/solidlsp/language_servers/csharp_language_server/initialize_params.json b/src/solidlsp/language_servers/csharp_language_server/initialize_params.json new file mode 100644 index 00000000..79ab5e7a --- /dev/null +++ b/src/solidlsp/language_servers/csharp_language_server/initialize_params.json @@ -0,0 +1,141 @@ +{ + "_description": "The parameters sent by the client when initializing the Microsoft.CodeAnalysis.LanguageServer with the \"initialize\" request. More details at https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize", + "processId": "os.getpid()", + "rootPath": "$rootPath", + "rootUri": "$rootUri", + "capabilities": { + "window": { + "workDoneProgress": true, + "showMessage": { + "messageActionItem": { + "additionalPropertiesSupport": true + } + }, + "showDocument": { + "support": true + } + }, + "workspace": { + "applyEdit": true, + "workspaceEdit": { + "documentChanges": true + }, + "didChangeConfiguration": { + "dynamicRegistration": true + }, + "didChangeWatchedFiles": { + "dynamicRegistration": true + }, + "symbol": { + "dynamicRegistration": true, + "symbolKind": { + "valueSet": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26] + } + }, + "executeCommand": { + "dynamicRegistration": true + }, + "configuration": true, + "workspaceFolders": true, + "workDoneProgress": true + }, + "textDocument": { + "synchronization": { + "dynamicRegistration": true, + "willSave": true, + "willSaveWaitUntil": true, + "didSave": true + }, + "completion": { + "dynamicRegistration": true, + "contextSupport": true, + "completionItem": { + "snippetSupport": true, + "commitCharactersSupport": true, + "documentationFormat": ["markdown", "plaintext"], + "deprecatedSupport": true, + "preselectSupport": true + }, + "completionItemKind": { + "valueSet": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25] + } + }, + "hover": { + "dynamicRegistration": true, + "contentFormat": ["markdown", "plaintext"] + }, + "signatureHelp": { + "dynamicRegistration": true, + "signatureInformation": { + "documentationFormat": ["markdown", "plaintext"], + "parameterInformation": { + "labelOffsetSupport": true + } + } + }, + "definition": { + "dynamicRegistration": true + }, + "references": { + "dynamicRegistration": true + }, + "documentHighlight": { + "dynamicRegistration": true + }, + "documentSymbol": { + "dynamicRegistration": true, + "symbolKind": { + "valueSet": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26] + }, + "hierarchicalDocumentSymbolSupport": true + }, + "codeAction": { + "dynamicRegistration": true, + "codeActionLiteralSupport": { + "codeActionKind": { + "valueSet": [ + "", + "quickfix", + "refactor", + "refactor.extract", + "refactor.inline", + "refactor.rewrite", + "source", + "source.organizeImports" + ] + } + } + }, + "codeLens": { + "dynamicRegistration": true + }, + "formatting": { + "dynamicRegistration": true + }, + "rangeFormatting": { + "dynamicRegistration": true + }, + "onTypeFormatting": { + "dynamicRegistration": true + }, + "rename": { + "dynamicRegistration": true + }, + "publishDiagnostics": { + "relatedInformation": true + }, + "foldingRange": { + "dynamicRegistration": true, + "rangeLimit": 5000, + "lineFoldingOnly": true + } + } + }, + "workspaceFolders": [ + { + "uri": "$rootUri", + "name": "$rootName" + } + ] +} +EOF < /dev/null