File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11from functools import lru_cache
22from sqlglot import Dialect , Tokenizer
3- from sqlmesh .lsp .custom import AllModelsResponse , MacroCompletion
3+ from sqlmesh .lsp .custom import (
4+ AllModelsResponse ,
5+ MacroCompletion ,
6+ ModelCompletion ,
7+ )
48from sqlmesh import macro
59import typing as t
610from sqlmesh .lsp .context import AuditTarget , LSPContext , ModelTarget
7- from sqlmesh .lsp .custom import ModelCompletion
811from sqlmesh .lsp .description import generate_markdown_description
912from sqlmesh .lsp .uri import URI
1013
@@ -30,8 +33,10 @@ def get_sql_completions(
3033 # Combine keywords - SQL keywords first, then file keywords
3134 all_keywords = list (sql_keywords ) + list (file_keywords - sql_keywords )
3235
36+ models = list (get_models (context , file_uri ))
3337 return AllModelsResponse (
34- models = list (get_models (context , file_uri )),
38+ models = [m .name for m in models ],
39+ model_completions = models ,
3540 keywords = all_keywords ,
3641 macros = list (get_macros (context , file_uri )),
3742 )
Original file line number Diff line number Diff line change @@ -38,11 +38,11 @@ class ModelCompletion(PydanticModel):
3838
3939
4040class AllModelsResponse (CustomMethodResponseBaseClass ):
41- """
42- Response to get all the models that are in the current project.
43- """
41+ """Response to get all models that are in the current project."""
4442
45- models : t .List [ModelCompletion ]
43+ #: Deprecated: use ``model_completions`` instead
44+ models : t .List [str ]
45+ model_completions : t .List [ModelCompletion ]
4646 keywords : t .List [str ]
4747 macros : t .List [MacroCompletion ]
4848
Original file line number Diff line number Diff line change @@ -680,7 +680,7 @@ def completion(
680680
681681 completion_items = []
682682 # Add model completions
683- for model in completion_response .models :
683+ for model in completion_response .model_completions :
684684 completion_items .append (
685685 types .CompletionItem (
686686 label = model .name ,
Original file line number Diff line number Diff line change @@ -41,6 +41,20 @@ def test_get_macros():
4141 assert add_one_macro .description
4242
4343
44+ def test_model_completions_include_descriptions ():
45+ context = Context (paths = ["examples/sushi" ])
46+ lsp_context = LSPContext (context )
47+
48+ completions = LSPContext .get_completions (lsp_context , None )
49+
50+ model_entry = next (
51+ (m for m in completions .model_completions if m .name == "sushi.customers" ),
52+ None ,
53+ )
54+ assert model_entry is not None
55+ assert model_entry .description
56+
57+
4458def test_get_sql_completions_with_context_no_file_uri ():
4559 context = Context (paths = ["examples/sushi" ])
4660 lsp_context = LSPContext (context )
Original file line number Diff line number Diff line change @@ -19,17 +19,10 @@ export const completionProvider = (
1919 if ( isErr ( result ) ) {
2020 return [ ]
2121 }
22- const modelCompletions = result . value . models . map ( model => {
23- const item = new vscode . CompletionItem (
24- model . name ,
25- vscode . CompletionItemKind . Reference ,
26- )
27- item . detail = 'SQLMesh Model'
28- if ( model . description ) {
29- item . documentation = new vscode . MarkdownString ( model . description )
30- }
31- return item
32- } )
22+ const modelCompletions = result . value . models . map (
23+ model =>
24+ new vscode . CompletionItem ( model , vscode . CompletionItemKind . Reference ) ,
25+ )
3326 const keywordCompletions = result . value . keywords . map (
3427 keyword =>
3528 new vscode . CompletionItem ( keyword , vscode . CompletionItemKind . Keyword ) ,
Original file line number Diff line number Diff line change @@ -25,16 +25,6 @@ export interface RenderModelEntry {
2525 rendered_query : string
2626}
2727
28- export interface ModelCompletion {
29- name : string
30- description : string | null | undefined
31- }
32-
33- export interface MacroCompletion {
34- name : string
35- description : string | null | undefined
36- }
37-
3828// @eslint -disable-next-line @typescript-eslint/consistent-type-definition
3929export type CustomLSPMethods =
4030 | AllModelsMethod
@@ -51,9 +41,8 @@ interface AllModelsRequest {
5141}
5242
5343interface AllModelsResponse {
54- models : ModelCompletion [ ]
44+ models : string [ ]
5545 keywords : string [ ]
56- macros : MacroCompletion [ ]
5746}
5847
5948export interface AbstractAPICallRequest {
You can’t perform that action at this time.
0 commit comments