Skip to content

Commit b2e7845

Browse files
authored
add support for code lenses (bump server to v4.1) (#223)
1 parent 206a725 commit b2e7845

File tree

5 files changed

+89
-22
lines changed

5 files changed

+89
-22
lines changed

LSP-typescript.sublime-settings

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,16 @@
4747
"settings": {
4848
"statusText": "$version, $source",
4949
"diagnostics.ignoredCodes": [],
50+
5051
// Implicit Project Configuration
5152
"implicitProjectConfiguration.checkJs": false,
5253
"implicitProjectConfiguration.experimentalDecorators": false,
5354
"implicitProjectConfiguration.module": "ESNext",
5455
"implicitProjectConfiguration.strictFunctionTypes": true,
5556
"implicitProjectConfiguration.strictNullChecks": true,
5657
"implicitProjectConfiguration.target": "ES2020",
57-
// Javascript formatting options.
58+
59+
// Formatting options.
5860
"javascript.format.insertSpaceAfterCommaDelimiter": true,
5961
"javascript.format.insertSpaceAfterConstructor": false,
6062
"javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": true,
@@ -74,16 +76,6 @@
7476
"javascript.format.placeOpenBraceOnNewLineForFunctions": false,
7577
"javascript.format.semicolons": "ignore", // ignore | insert | remove
7678
"javascript.format.trimTrailingWhitespace": true,
77-
// Javascript inlay hints options.
78-
"javascript.inlayHints.includeInlayEnumMemberValueHints": false,
79-
"javascript.inlayHints.includeInlayFunctionLikeReturnTypeHints": false,
80-
"javascript.inlayHints.includeInlayFunctionParameterTypeHints": false,
81-
"javascript.inlayHints.includeInlayParameterNameHints": "none", // none | literals | all
82-
"javascript.inlayHints.includeInlayParameterNameHintsWhenArgumentMatchesName": false,
83-
"javascript.inlayHints.includeInlayPropertyDeclarationTypeHints": false,
84-
"javascript.inlayHints.includeInlayVariableTypeHints": false,
85-
"javascript.inlayHints.includeInlayVariableTypeHintsWhenTypeMatchesName": false,
86-
// Typescript formatting options.
8779
"typescript.format.insertSpaceAfterCommaDelimiter": true,
8880
"typescript.format.insertSpaceAfterConstructor": false,
8981
"typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": true,
@@ -103,7 +95,16 @@
10395
"typescript.format.placeOpenBraceOnNewLineForFunctions": false,
10496
"typescript.format.semicolons": "ignore", // ignore | insert | remove
10597
"typescript.format.trimTrailingWhitespace": true,
106-
// Typescript inlay hints options.
98+
99+
// Inlay hints options.
100+
"javascript.inlayHints.includeInlayEnumMemberValueHints": false,
101+
"javascript.inlayHints.includeInlayFunctionLikeReturnTypeHints": false,
102+
"javascript.inlayHints.includeInlayFunctionParameterTypeHints": false,
103+
"javascript.inlayHints.includeInlayParameterNameHints": "none", // none | literals | all
104+
"javascript.inlayHints.includeInlayParameterNameHintsWhenArgumentMatchesName": false,
105+
"javascript.inlayHints.includeInlayPropertyDeclarationTypeHints": false,
106+
"javascript.inlayHints.includeInlayVariableTypeHints": false,
107+
"javascript.inlayHints.includeInlayVariableTypeHintsWhenTypeMatchesName": false,
107108
"typescript.inlayHints.includeInlayEnumMemberValueHints": false,
108109
"typescript.inlayHints.includeInlayFunctionLikeReturnTypeHints": false,
109110
"typescript.inlayHints.includeInlayFunctionParameterTypeHints": false,
@@ -112,6 +113,14 @@
112113
"typescript.inlayHints.includeInlayPropertyDeclarationTypeHints": false,
113114
"typescript.inlayHints.includeInlayVariableTypeHints": false,
114115
"typescript.inlayHints.includeInlayVariableTypeHintsWhenTypeMatchesName": false,
116+
117+
// Code Lens options.
118+
"javascript.implementationsCodeLens.enabled": false,
119+
"javascript.referencesCodeLens.enabled": false,
120+
"javascript.referencesCodeLens.showOnAllFunctions": false,
121+
"typescript.implementationsCodeLens.enabled": false,
122+
"typescript.referencesCodeLens.enabled": false,
123+
"typescript.referencesCodeLens.showOnAllFunctions": false,
115124
},
116125
"command": ["${node_bin}", "${server_path}", "--stdio"],
117126
"selector": "source.js, source.jsx, source.ts, source.tsx",

plugin.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from .plugin_types import TypescriptVersionNotificationParams
2+
from LSP.plugin import Session
23
from LSP.plugin import uri_to_filename
3-
from LSP.plugin.core.protocol import Point, TextDocumentPositionParams
4-
from LSP.plugin.core.typing import Callable, Tuple
4+
from LSP.plugin.core.protocol import Location, Point, TextDocumentPositionParams
5+
from LSP.plugin.core.typing import Any, Callable, List, Mapping, Tuple
56
from LSP.plugin.core.views import point_to_offset
7+
from LSP.plugin.locationpicker import LocationPicker
68
from lsp_utils import notification_handler
79
from lsp_utils import NpmClientHandler
810
from lsp_utils import request_handler
@@ -52,3 +54,29 @@ def on_typescript_version_async(self, params: TypescriptVersionNotificationParam
5254
status_text = version_template.replace('$version', params['version']).replace('$source', params['source'])
5355
if status_text:
5456
session.set_config_status_async(status_text)
57+
58+
def on_pre_server_command(self, command: Mapping[str, Any], done_callback: Callable[[], None]) -> bool:
59+
command_name = command['command']
60+
if command_name == 'editor.action.showReferences':
61+
session = self.weaksession()
62+
if not session:
63+
return False
64+
self._handle_show_references(session, command['arguments'][2])
65+
done_callback()
66+
return True
67+
return False
68+
69+
def _handle_show_references(self, session: Session, references: List[Location]) -> None:
70+
view = session.window.active_view()
71+
if not view:
72+
return
73+
if len(references) == 1:
74+
args = {
75+
'location': references[0],
76+
'session_name': session.config.name,
77+
}
78+
session.window.run_command('lsp_open_location', args)
79+
elif references:
80+
LocationPicker(view, session, references, side_by_side=False)
81+
else:
82+
sublime.status_message('No references found')

sublime-package.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,36 @@
521521
"default": false,
522522
"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."
523523
},
524+
"javascript.implementationsCodeLens.enabled": {
525+
"type": "boolean",
526+
"default": false,
527+
"markdownDescription": "Enable/disable implementations CodeLens. This CodeLens shows the implementers of an interface."
528+
},
529+
"javascript.referencesCodeLens.enabled": {
530+
"type": "boolean",
531+
"default": false,
532+
"markdownDescription": "Enable/disable references CodeLens in JavaScript files."
533+
},
534+
"javascript.referencesCodeLens.showOnAllFunctions": {
535+
"type": "boolean",
536+
"default": false,
537+
"markdownDescription": "Enable/disable references CodeLens on all functions in JavaScript files."
538+
},
539+
"typescript.implementationsCodeLens.enabled": {
540+
"type": "boolean",
541+
"default": false,
542+
"markdownDescription": "Enable/disable implementations CodeLens. This CodeLens shows the implementers of an interface."
543+
},
544+
"typescript.referencesCodeLens.enabled": {
545+
"type": "boolean",
546+
"default": false,
547+
"markdownDescription": "Enable/disable references CodeLens in TypeScript files."
548+
},
549+
"typescript.referencesCodeLens.showOnAllFunctions": {
550+
"type": "boolean",
551+
"default": false,
552+
"markdownDescription": "Enable/disable references CodeLens on all functions in TypeScript files."
553+
},
524554
"javascript.format.insertSpaceAfterCommaDelimiter": {
525555
"type": "boolean",
526556
"default": true

typescript-language-server/package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typescript-language-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"private": true,
44
"dependencies": {
55
"typescript": "5.2.2",
6-
"typescript-language-server": "4.0.0"
6+
"typescript-language-server": "4.1.0"
77
}
88
}

0 commit comments

Comments
 (0)