Skip to content

Commit

Permalink
add support for code lenses (bump server to v4.1) (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl authored Nov 9, 2023
1 parent 206a725 commit b2e7845
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 22 deletions.
33 changes: 21 additions & 12 deletions LSP-typescript.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@
"settings": {
"statusText": "$version, $source",
"diagnostics.ignoredCodes": [],

// Implicit Project Configuration
"implicitProjectConfiguration.checkJs": false,
"implicitProjectConfiguration.experimentalDecorators": false,
"implicitProjectConfiguration.module": "ESNext",
"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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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",
Expand Down
32 changes: 30 additions & 2 deletions plugin.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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')
30 changes: 30 additions & 0 deletions sublime-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions typescript-language-server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion typescript-language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"private": true,
"dependencies": {
"typescript": "5.2.2",
"typescript-language-server": "4.0.0"
"typescript-language-server": "4.1.0"
}
}

0 comments on commit b2e7845

Please sign in to comment.