Skip to content

Commit 50a105a

Browse files
committed
feat(vscode): multi project for vscode
- [ ] needs testin
1 parent 3bbb819 commit 50a105a

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

sqlmesh/lsp/main.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,20 @@
7171
from sqlmesh.lsp.uri import URI
7272
from sqlmesh.utils.errors import ConfigError
7373
from sqlmesh.utils.lineage import ExternalModelReference
74+
from sqlmesh.utils.pydantic import PydanticModel
7475
from web.server.api.endpoints.lineage import column_lineage, model_lineage
7576
from web.server.api.endpoints.models import get_models
7677
from typing import Union
7778
from dataclasses import dataclass, field
7879

7980

81+
class InitializationOptions(PydanticModel):
82+
"""Initialization options for the SQLMesh Language Server, that
83+
are passed from the client to the server."""
84+
85+
project_paths: t.Optional[t.List[str]] = None
86+
87+
8088
@dataclass
8189
class NoContext:
8290
"""State when no context has been attempted to load."""
@@ -105,6 +113,11 @@ class ContextFailed:
105113

106114

107115
class SQLMeshLanguageServer:
116+
# Specified folders take precedence over workspace folders or looking
117+
# for a config files. They are explicitly set by the user and optionally
118+
# pass in at init
119+
specified_paths: t.Optional[t.List[Path]] = None
120+
108121
def __init__(
109122
self,
110123
context_class: t.Type[Context],
@@ -411,6 +424,12 @@ def command_external_models_update_columns(ls: LanguageServer, raw: t.Any) -> No
411424
def initialize(ls: LanguageServer, params: types.InitializeParams) -> None:
412425
"""Initialize the server when the client connects."""
413426
try:
427+
# Check the custom options
428+
if params.initialization_options:
429+
options = InitializationOptions.model_validate(params.initialization_options)
430+
if options.project_paths is not None:
431+
self.specified_paths = [Path(path) for path in options.project_paths]
432+
414433
# Check if the client supports pull diagnostics
415434
if params.capabilities and params.capabilities.text_document:
416435
diagnostics = getattr(params.capabilities.text_document, "diagnostic", None)
@@ -906,7 +925,12 @@ def _context_get_or_load(self, document_uri: t.Optional[URI] = None) -> LSPConte
906925
raise Exception(state.error)
907926
raise state.error
908927
if isinstance(state, NoContext):
909-
self._ensure_context_for_document(document_uri)
928+
if self.specified_paths is not None:
929+
# If specified paths are provided, create context from them
930+
if self._create_lsp_context(self.specified_paths):
931+
loaded_sqlmesh_message(self.server)
932+
else:
933+
self._ensure_context_for_document(document_uri)
910934
if isinstance(state, ContextLoaded):
911935
return state.lsp_context
912936
raise RuntimeError("Context failed to load")

vscode/extension/src/lsp/lsp.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ export class LSPClient implements Disposable {
117117
],
118118
diagnosticCollectionName: 'sqlmesh',
119119
outputChannel,
120+
initializationOptions: {
121+
project_paths: ['test1', 'test2'],
122+
},
120123
}
121124

122125
traceInfo(

0 commit comments

Comments
 (0)