From 9cc8db3fec58146c68064c142836b46894181d4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D1=80=D0=B5=D0=B4=D1=80=D0=B0=D0=B3=20=D0=9D=D0=B8?= =?UTF-8?q?=D0=BA=D0=BE=D0=BB=D0=B8=D1=9B?= Date: Wed, 27 Apr 2022 12:44:46 -0700 Subject: [PATCH] Update JSON schema (#77) * update json schema Some settings have been skipped, because they are VS Code related, or they are simply not supported: "volar-language-features.trace.server" - Traces the communication between VS Code and the language server. "volar-language-features-2.trace.server" - Traces the communication between VS Code and the language server. "volar-document-features.trace.server" - Traces the communication between VS Code and the language server. "volar.vueserver.useSecondServer" - Not supported "volar.icon.splitEditors" - Not supported - Show split editor icon in title area of editor. "volar.icon.preview" - Not supported - Show Vite / Nuxt App preview icon. "volar.takeOverMode.enabled" - Skipped, because LSP-volar does it this way https://github.com/sublimelsp/LSP-volar#enable-for-non-vue-files "volar.preview.port" - Not supported, yet "volar.preview.backgroundColor" - Not supported "volar.preview.transparentGrid" - Not supported DEPRECATIONS "volar.preferredAttrNameCase" was renamed to "volar.completion.preferredAttrNameCase" "volar.preferredTagNameCase" was renamed to "volar.completion.preferredTagNameCase" * LSP supports implementation https://github.com/johnsoncodehk/volar/blob/master/CHANGELOG.md#0330-2022313 > eat: support for goto implementations if you're not using VSCode, you should config new option languageFeatures.implementation = true in initializationOptions to enable it * LSP doesn't supports inlay hints just yet * refactor: define a find_typescript_path method * programmatically set initialization options for languageFeatures and documentFeatures --- LSP-volar.sublime-settings | 39 +++--------------------- plugin.py | 61 ++++++++++++++++++++++++++++++++++++-- sublime-package.json | 30 +++++++++++-------- 3 files changed, 79 insertions(+), 51 deletions(-) diff --git a/LSP-volar.sublime-settings b/LSP-volar.sublime-settings index aeea9b9..0551576 100644 --- a/LSP-volar.sublime-settings +++ b/LSP-volar.sublime-settings @@ -6,48 +6,17 @@ // else the typescript bundled with LSP-volar will be used. "typescript": { // "serverPath": "/path/to/tsserverlibrary.js" - }, - "languageFeatures": { - "references": true, - "definition": true, - "typeDefinition": true, - "callHierarchy": false, - "hover": true, - "rename": true, - "renameFileRefactoring": false, - "signatureHelp": true, - "codeAction": true, - "completion": { - "defaultTagNameCase": "both", - "defaultAttrNameCase": "kebab", - "getDocumentNameCasesRequest": false, - "getDocumentSelectionRequest": false, - }, - "documentHighlight": true, - "documentLink": false, - "codeLens": false, - "semanticTokens": false, - "schemaRequestService": false, - "diagnostics": true - }, - "documentFeatures": { - "selectionRange": true, - "foldingRange": true, - "linkedEditingRange": false, - "documentSymbol": true, - "documentColor": true, - "documentFormatting": { - "defaultPrintWidth": 90 - } } }, "settings": { "volar.codeLens.references": true, "volar.codeLens.pugTools": false, "volar.codeLens.scriptSetupTools": false, + "volar.autoWrapParentheses": true, + "volar.autoCompleteRefs": false, "volar.completion.autoImportComponent": true, - "volar.preferredAttrNameCase": "auto-kebab", - "volar.preferredTagNameCase": "auto" + "volar.completion.preferredAttrNameCase": "kebab", + "volar.completion.preferredTagNameCase": "both" }, "languages": [ { diff --git a/plugin.py b/plugin.py index 9a3236d..feb40f8 100644 --- a/plugin.py +++ b/plugin.py @@ -30,12 +30,51 @@ def is_allowed_to_start( ): if not workspace_folders or not configuration: return + configuration.init_options.set('languageFeatures', { + "references": True, + "definition": True, + "implementation": True, + "typeDefinition": True, + "callHierarchy": False, + "inlayHints": False, + "hover": True, + "rename": True, + "renameFileRefactoring": False, + "signatureHelp": True, + "codeAction": True, + "completion": { + "defaultTagNameCase": get_default_tag_name_case(configuration), + "defaultAttrNameCase": get_default_attr_name_case(configuration), + "getDocumentNameCasesRequest": False, + "getDocumentSelectionRequest": False, + }, + "documentHighlight": True, + "documentLink": False, + "codeLens": False, + "semanticTokens": False, + "schemaRequestService": False, + "diagnostics": True + }) + configuration.init_options.set('documentFeatures', { + "selectionRange": True, + "foldingRange": True, + "linkedEditingRange": False, + "documentSymbol": True, + "documentColor": True, + "documentFormatting": { + "defaultPrintWidth": 90 + } + }) if configuration.init_options.get('typescript.serverPath'): return # don't find the `typescript.serverPath` if it was set explicitly in LSP-volar.sublime-settings + typescript_path = LspVolarPlugin.find_typescript_path(workspace_folders[0].path) + configuration.init_options.set('typescript.serverPath', typescript_path) + + @classmethod + def find_typescript_path(cls, current_folder: str) -> str: server_directory_path = cls._server_directory_path() resolve_module_script = os.path.join(server_directory_path, 'resolve_module.js') - first_folder = workspace_folders[0].path - find_ts_server_command = [cls._node_bin(), resolve_module_script, first_folder] + find_ts_server_command = [cls._node_bin(), resolve_module_script, current_folder] startupinfo = None # Prevent cmd.exe popup on Windows. if sublime.platform() == "windows": @@ -45,4 +84,20 @@ def is_allowed_to_start( ) workspace_ts_path = subprocess.check_output(find_ts_server_command, universal_newlines=True, startupinfo=startupinfo) bundled_ts_path = os.path.join(server_directory_path, 'node_modules', 'typescript', 'lib', 'tsserverlibrary.js') - configuration.init_options.set('typescript.serverPath', workspace_ts_path or bundled_ts_path) + return workspace_ts_path or bundled_ts_path + + +def get_default_tag_name_case(configuration: ClientConfig) -> str: + preferred_tag_name_case = configuration.settings.get('volar.completion.preferredTagNameCase') + if preferred_tag_name_case == 'kebab': + return 'kebabCase' + elif preferred_tag_name_case == 'pascal': + return 'pascalCase' + return 'both' + + +def get_default_attr_name_case(configuration: ClientConfig) -> str: + preferred_attr_name_case = configuration.settings.get('volar.completion.preferredAttrNameCase') + if preferred_attr_name_case == 'camel': + return 'camelCase' + return 'kebabCase' diff --git a/sublime-package.json b/sublime-package.json index d3626ee..0a86247 100644 --- a/sublime-package.json +++ b/sublime-package.json @@ -28,38 +28,42 @@ "default": false, "description": "[ref sugar ☐] code lens." }, - "volar.preferredTagNameCase": { + "volar.autoWrapParentheses": { + "type": "boolean", + "default": true, + "description": "Auto-wrap `()` to As Expression in interpolations for fix issue #520." + }, + "volar.autoCompleteRefs": { + "type": "boolean", + "default": false, + "description": "Auto-complete Ref value with `.value`." + }, + "volar.completion.preferredTagNameCase": { "type": "string", "enum": [ - "auto", "both", "kebab", "pascal" ], "enumDescriptions": [ - "Auto Detect from Content", " and ", "", "" ], - "default": "auto", + "default": "both", "description": "Preferred tag name case." }, - "volar.preferredAttrNameCase": { + "volar.completion.preferredAttrNameCase": { "type": "string", "enum": [ - "auto-kebab", - "auto-pascal", "kebab", - "pascal" + "camel" ], "enumDescriptions": [ - "Auto Detect from Content (Preference kebab-case)", - "Auto Detect from Content (Preference pascalCase)", - "kebab-case", - "pascalCase" + ":kebab-case=\"...\"", + ":camelCase=\"...\"" ], - "default": "auto-kebab", + "default": "kebab", "description": "Preferred attr name case." }, "volar.completion.autoImportComponent": {