diff --git a/LSP-typescript.sublime-settings b/LSP-typescript.sublime-settings index 3068485..3de6b0c 100644 --- a/LSP-typescript.sublime-settings +++ b/LSP-typescript.sublime-settings @@ -47,6 +47,7 @@ "settings": { "statusText": "$version, $source", "diagnostics.ignoredCodes": [], + // Implicit Project Configuration "implicitProjectConfiguration.checkJs": false, "implicitProjectConfiguration.experimentalDecorators": false, @@ -54,7 +55,8 @@ "implicitProjectConfiguration.strictFunctionTypes": true, "implicitProjectConfiguration.strictNullChecks": true, "implicitProjectConfiguration.target": "ES2020", - // Javascript formatting options. + + // Formatting options. "javascript.format.insertSpaceAfterCommaDelimiter": true, "javascript.format.insertSpaceAfterConstructor": false, "javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": true, @@ -74,16 +76,6 @@ "javascript.format.placeOpenBraceOnNewLineForFunctions": false, "javascript.format.semicolons": "ignore", // ignore | insert | remove "javascript.format.trimTrailingWhitespace": true, - // Javascript inlay hints options. - "javascript.inlayHints.includeInlayEnumMemberValueHints": false, - "javascript.inlayHints.includeInlayFunctionLikeReturnTypeHints": false, - "javascript.inlayHints.includeInlayFunctionParameterTypeHints": false, - "javascript.inlayHints.includeInlayParameterNameHints": "none", // none | literals | all - "javascript.inlayHints.includeInlayParameterNameHintsWhenArgumentMatchesName": false, - "javascript.inlayHints.includeInlayPropertyDeclarationTypeHints": false, - "javascript.inlayHints.includeInlayVariableTypeHints": false, - "javascript.inlayHints.includeInlayVariableTypeHintsWhenTypeMatchesName": false, - // Typescript formatting options. "typescript.format.insertSpaceAfterCommaDelimiter": true, "typescript.format.insertSpaceAfterConstructor": false, "typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": true, @@ -103,7 +95,16 @@ "typescript.format.placeOpenBraceOnNewLineForFunctions": false, "typescript.format.semicolons": "ignore", // ignore | insert | remove "typescript.format.trimTrailingWhitespace": true, - // Typescript inlay hints options. + + // Inlay hints options. + "javascript.inlayHints.includeInlayEnumMemberValueHints": false, + "javascript.inlayHints.includeInlayFunctionLikeReturnTypeHints": false, + "javascript.inlayHints.includeInlayFunctionParameterTypeHints": false, + "javascript.inlayHints.includeInlayParameterNameHints": "none", // none | literals | all + "javascript.inlayHints.includeInlayParameterNameHintsWhenArgumentMatchesName": false, + "javascript.inlayHints.includeInlayPropertyDeclarationTypeHints": false, + "javascript.inlayHints.includeInlayVariableTypeHints": false, + "javascript.inlayHints.includeInlayVariableTypeHintsWhenTypeMatchesName": false, "typescript.inlayHints.includeInlayEnumMemberValueHints": false, "typescript.inlayHints.includeInlayFunctionLikeReturnTypeHints": false, "typescript.inlayHints.includeInlayFunctionParameterTypeHints": false, @@ -112,6 +113,14 @@ "typescript.inlayHints.includeInlayPropertyDeclarationTypeHints": false, "typescript.inlayHints.includeInlayVariableTypeHints": false, "typescript.inlayHints.includeInlayVariableTypeHintsWhenTypeMatchesName": false, + + // Code Lens options. + "javascript.implementationsCodeLens.enabled": false, + "javascript.referencesCodeLens.enabled": false, + "javascript.referencesCodeLens.showOnAllFunctions": false, + "typescript.implementationsCodeLens.enabled": false, + "typescript.referencesCodeLens.enabled": false, + "typescript.referencesCodeLens.showOnAllFunctions": false, }, "command": ["${node_bin}", "${server_path}", "--stdio"], "selector": "source.js, source.jsx, source.ts, source.tsx", diff --git a/plugin.py b/plugin.py index 070fc25..55bcc52 100644 --- a/plugin.py +++ b/plugin.py @@ -1,8 +1,10 @@ from .plugin_types import TypescriptVersionNotificationParams +from LSP.plugin import Session from LSP.plugin import uri_to_filename -from LSP.plugin.core.protocol import Point, TextDocumentPositionParams -from LSP.plugin.core.typing import Callable, Tuple +from LSP.plugin.core.protocol import Location, Point, TextDocumentPositionParams +from LSP.plugin.core.typing import Any, Callable, List, Mapping, Tuple from LSP.plugin.core.views import point_to_offset +from LSP.plugin.locationpicker import LocationPicker from lsp_utils import notification_handler from lsp_utils import NpmClientHandler from lsp_utils import request_handler @@ -52,3 +54,29 @@ def on_typescript_version_async(self, params: TypescriptVersionNotificationParam status_text = version_template.replace('$version', params['version']).replace('$source', params['source']) if status_text: session.set_config_status_async(status_text) + + def on_pre_server_command(self, command: Mapping[str, Any], done_callback: Callable[[], None]) -> bool: + command_name = command['command'] + if command_name == 'editor.action.showReferences': + session = self.weaksession() + if not session: + return False + self._handle_show_references(session, command['arguments'][2]) + done_callback() + return True + return False + + def _handle_show_references(self, session: Session, references: List[Location]) -> None: + view = session.window.active_view() + if not view: + return + if len(references) == 1: + args = { + 'location': references[0], + 'session_name': session.config.name, + } + session.window.run_command('lsp_open_location', args) + elif references: + LocationPicker(view, session, references, side_by_side=False) + else: + sublime.status_message('No references found') diff --git a/sublime-package.json b/sublime-package.json index 15a14f9..455b39c 100644 --- a/sublime-package.json +++ b/sublime-package.json @@ -521,6 +521,36 @@ "default": false, "markdownDescription": "When disabled then type hints on variables whose name is identical to the type name won't be shown. Requires using TypeScript 4.8+ in the workspace." }, + "javascript.implementationsCodeLens.enabled": { + "type": "boolean", + "default": false, + "markdownDescription": "Enable/disable implementations CodeLens. This CodeLens shows the implementers of an interface." + }, + "javascript.referencesCodeLens.enabled": { + "type": "boolean", + "default": false, + "markdownDescription": "Enable/disable references CodeLens in JavaScript files." + }, + "javascript.referencesCodeLens.showOnAllFunctions": { + "type": "boolean", + "default": false, + "markdownDescription": "Enable/disable references CodeLens on all functions in JavaScript files." + }, + "typescript.implementationsCodeLens.enabled": { + "type": "boolean", + "default": false, + "markdownDescription": "Enable/disable implementations CodeLens. This CodeLens shows the implementers of an interface." + }, + "typescript.referencesCodeLens.enabled": { + "type": "boolean", + "default": false, + "markdownDescription": "Enable/disable references CodeLens in TypeScript files." + }, + "typescript.referencesCodeLens.showOnAllFunctions": { + "type": "boolean", + "default": false, + "markdownDescription": "Enable/disable references CodeLens on all functions in TypeScript files." + }, "javascript.format.insertSpaceAfterCommaDelimiter": { "type": "boolean", "default": true diff --git a/typescript-language-server/package-lock.json b/typescript-language-server/package-lock.json index bfe75e9..328fcca 100644 --- a/typescript-language-server/package-lock.json +++ b/typescript-language-server/package-lock.json @@ -7,7 +7,7 @@ "name": "lsp-typescript", "dependencies": { "typescript": "5.2.2", - "typescript-language-server": "4.0.0" + "typescript-language-server": "4.1.0" } }, "node_modules/typescript": { @@ -23,9 +23,9 @@ } }, "node_modules/typescript-language-server": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/typescript-language-server/-/typescript-language-server-4.0.0.tgz", - "integrity": "sha512-u6GLfWtHzOfGNpn0XuUYFg8Jv3oXWKzY6o5/Lt6LbWE6Ux965z2lP+vM0AN8Z2EobnlrDzzdcKusUx46j2eP3A==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/typescript-language-server/-/typescript-language-server-4.1.0.tgz", + "integrity": "sha512-VbEw1U0jKKQ7pIYRtfQzBl7BroRBWSuS8x483jY0n4sQc0A8P7PgeSb3OycRbaj1rkfsTXZhsxKmsRYmoXAbdw==", "bin": { "typescript-language-server": "lib/cli.mjs" }, @@ -41,9 +41,9 @@ "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==" }, "typescript-language-server": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/typescript-language-server/-/typescript-language-server-4.0.0.tgz", - "integrity": "sha512-u6GLfWtHzOfGNpn0XuUYFg8Jv3oXWKzY6o5/Lt6LbWE6Ux965z2lP+vM0AN8Z2EobnlrDzzdcKusUx46j2eP3A==" + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/typescript-language-server/-/typescript-language-server-4.1.0.tgz", + "integrity": "sha512-VbEw1U0jKKQ7pIYRtfQzBl7BroRBWSuS8x483jY0n4sQc0A8P7PgeSb3OycRbaj1rkfsTXZhsxKmsRYmoXAbdw==" } } } diff --git a/typescript-language-server/package.json b/typescript-language-server/package.json index 59a6c8a..7095fea 100644 --- a/typescript-language-server/package.json +++ b/typescript-language-server/package.json @@ -3,6 +3,6 @@ "private": true, "dependencies": { "typescript": "5.2.2", - "typescript-language-server": "4.0.0" + "typescript-language-server": "4.1.0" } }