Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions plugin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from __future__ import annotations
from .plugin_types import TypescriptVersionNotificationParams
from LSP.plugin import ClientConfig
from LSP.plugin import Session
from LSP.plugin import uri_to_filename
from LSP.plugin import WorkspaceFolder
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 NodeRuntime
from lsp_utils import notification_handler
from lsp_utils import NpmClientHandler
from lsp_utils import request_handler
Expand All @@ -29,6 +33,16 @@ class LspTypescriptPlugin(NpmClientHandler):
def minimum_node_version(cls) -> Tuple[int, int, int]:
return (14, 16, 0)

@classmethod
def on_pre_start(
cls,
window: sublime.Window,
initiating_view: sublime.View,
workspace_folders: list[WorkspaceFolder],
configuration: ClientConfig,
) -> str | None:
cls._support_vue_hybrid_mode(configuration)
Comment on lines +36 to +44
Copy link
Member

@rchl rchl Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problems:

  • This will not trigger until one opens a supported file type (ts/js/..). So none of this logic will run when just opening a *.vue file.
  • This changes global LSP-typescript settings so the vue plugin will be enabled for every project/file once some *.vue file is opened. Doesn't seem ideal. I wouldn't trust the vue plugin enough to enable it at all times, for all projects.

Copy link

@niksy niksy Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not trigger until one opens a supported file type (ts/js/..). So none of this logic will run when just opening a *.vue file.

Is the simple solution to manually add text.html.vue to LSP-typescript selector setting? Maybe this could be mentioned in installation instructions as prerequisite step.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should avoid all the magic if we can: sublimelsp/LSP-vue#136 (comment)


@request_handler('_typescript.rename')
def on_typescript_rename(self, params: TextDocumentPositionParams, respond: Callable[[None], None]) -> None:
filename = uri_to_filename(params['textDocument']['uri'])
Expand Down Expand Up @@ -80,3 +94,35 @@ def _handle_show_references(self, session: Session, references: List[Location])
LocationPicker(view, session, references, side_by_side=False)
else:
sublime.status_message('No references found')

@classmethod
def _support_vue_hybrid_mode(cls, configuration: ClientConfig) -> None:
vue_settings = sublime.load_settings('LSP-vue.sublime-settings')
if not vue_settings:
return
vue_hybrid_mode = vue_settings.get('initializationOptions', {}).get('vue.hybridMode', False)
if not vue_hybrid_mode:
return
node_version = None
node_runtime = NodeRuntime.get('LSP-vue', cls.storage_path(), '*')
if node_runtime:
node_version = str(node_runtime.resolve_version())
if not node_version:
return
configuration.init_options.update({
"plugins": [
{
"languages": ["vue"],
"location": os.path.join(cls._vue_package_storage_path(), node_version, 'server','node_modules'),
"name": "@vue/typescript-plugin",
}
],
})
configuration.selector = 'source.js, source.jsx, source.ts, source.tsx, text.html.vue'

@classmethod
def _vue_package_storage_path(cls) -> str:
"""
The storage path for this package. Its path is '$DATA/Package Storage/[Package_Name]'.
"""
return os.path.join(cls.storage_path(), 'LSP-vue')