Skip to content

Commit fa51b32

Browse files
committed
temp [ci skip]
1 parent 1eced3c commit fa51b32

12 files changed

Lines changed: 38 additions & 93 deletions

File tree

examples/sushi/models/latest_order.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@ MODEL (
1212
SELECT id, customer_id, start_ts, end_ts, event_date
1313
FROM sushi.orders
1414
ORDER BY event_date DESC LIMIT 1
15-

sqlmesh/lsp/api.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ApiRequest(PydanticModel):
1919
Request to call the SQLMesh API.
2020
This is a generic request that can be used to call any API endpoint.
2121
"""
22+
2223
requestId: str
2324
url: str
2425
method: t.Optional[str] = "GET"
@@ -41,23 +42,29 @@ class ApiResponseGetModels(ApiResponse):
4142
Response from the SQLMesh API for the get_models endpoint.
4243
Specifies the data type more precisely as a list of models.
4344
"""
45+
4446
data: t.List[Model]
45-
47+
4648
def __init__(self, **data):
4749
# Convert datetime objects to strings before passing to parent constructor
4850
if "data" in data and isinstance(data["data"], list):
4951
for model in data["data"]:
5052
if hasattr(model, "details") and model.details:
5153
# Convert datetime fields to None or string to avoid serialization issues
5254
for field in ["stamp", "start", "cron_prev", "cron_next"]:
53-
if hasattr(model.details, field) and getattr(model.details, field) is not None:
55+
if (
56+
hasattr(model.details, field)
57+
and getattr(model.details, field) is not None
58+
):
5459
setattr(model.details, field, None)
55-
60+
5661
super().__init__(**data)
5762

63+
5864
class ApiResponseGetLineage(ApiResponse):
5965
"""
6066
Response from the SQLMesh API for the get_lineage endpoint.
6167
Specifies the data type more precisely as a list of models.
6268
"""
69+
6370
data: t.Dict[str, t.List[str]]

sqlmesh/lsp/main.py

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111
from sqlmesh._version import __version__
1212
from sqlmesh.core.context import Context
1313
from sqlmesh.core.linter.definition import AnnotatedRuleViolation
14-
from sqlmesh.lsp.api import API_FEATURE, ApiRequest, ApiResponse, ApiResponseGetLineage, ApiResponseGetModels
14+
from sqlmesh.lsp.api import (
15+
API_FEATURE,
16+
ApiRequest,
17+
ApiResponse,
18+
ApiResponseGetLineage,
19+
ApiResponseGetModels,
20+
)
1521
from sqlmesh.lsp.completions import get_sql_completions
1622
from sqlmesh.lsp.context import LSPContext
1723
from sqlmesh.lsp.custom import ALL_MODELS_FEATURE, AllModelsRequest, AllModelsResponse
@@ -44,9 +50,7 @@ def _register_features(self) -> None:
4450
"""Register LSP features on the internal LanguageServer instance."""
4551

4652
@self.server.feature(ALL_MODELS_FEATURE)
47-
def all_models(
48-
ls: LanguageServer, params: AllModelsRequest
49-
) -> AllModelsResponse:
53+
def all_models(ls: LanguageServer, params: AllModelsRequest) -> AllModelsResponse:
5054
try:
5155
context = self._context_get_or_load(params.textDocument.uri)
5256
return get_sql_completions(context, params.textDocument.uri)
@@ -60,19 +64,16 @@ def api(ls: LanguageServer, request: ApiRequest) -> ApiResponse:
6064
return ApiResponse(data={})
6165
if request.url == "/api/models":
6266
response = ApiResponseGetModels(data=get_models(self.lsp_context.context))
63-
return response
64-
elif request.url.startswith("/api/lineage"):
67+
return response
68+
if request.url.startswith("/api/lineage"):
6569
name = request.url.split("/")[-1]
6670
lineage = model_lineage(name, self.lsp_context.context)
6771
non_set_lineage = {k: v for k, v in lineage.items() if v is not None}
68-
response = ApiResponseGetLineage(data=non_set_lineage)
69-
return response
72+
return ApiResponseGetLineage(data=non_set_lineage)
7073
raise NotImplementedError(f"API request not implemented: {request.url}")
7174

7275
@self.server.feature(types.TEXT_DOCUMENT_DID_OPEN)
73-
def did_open(
74-
ls: LanguageServer, params: types.DidOpenTextDocumentParams
75-
) -> None:
76+
def did_open(ls: LanguageServer, params: types.DidOpenTextDocumentParams) -> None:
7677
context = self._context_get_or_load(params.text_document.uri)
7778
if self.lint_cache.get(params.text_document.uri) is not None:
7879
ls.publish_diagnostics(
@@ -97,9 +98,7 @@ def did_open(
9798
)
9899

99100
@self.server.feature(types.TEXT_DOCUMENT_DID_CHANGE)
100-
def did_change(
101-
ls: LanguageServer, params: types.DidChangeTextDocumentParams
102-
) -> None:
101+
def did_change(ls: LanguageServer, params: types.DidChangeTextDocumentParams) -> None:
103102
context = self._context_get_or_load(params.text_document.uri)
104103
models = context.map[params.text_document.uri]
105104
if models is None:
@@ -116,9 +115,7 @@ def did_change(
116115
)
117116

118117
@self.server.feature(types.TEXT_DOCUMENT_DID_SAVE)
119-
def did_save(
120-
ls: LanguageServer, params: types.DidSaveTextDocumentParams
121-
) -> None:
118+
def did_save(ls: LanguageServer, params: types.DidSaveTextDocumentParams) -> None:
122119
context = self._context_get_or_load(params.text_document.uri)
123120
models = context.map[params.text_document.uri]
124121
if models is None:
@@ -143,9 +140,7 @@ def formatting(
143140
self._ensure_context_for_document(params.text_document.uri)
144141
document = ls.workspace.get_document(params.text_document.uri)
145142
if self.lsp_context is None:
146-
raise RuntimeError(
147-
f"No context found for document: {document.path}"
148-
)
143+
raise RuntimeError(f"No context found for document: {document.path}")
149144

150145
# Perform formatting using the loaded context
151146
self.lsp_context.context.format(paths=(Path(document.path),))
@@ -159,9 +154,7 @@ def formatting(
159154
start=types.Position(line=0, character=0),
160155
end=types.Position(
161156
line=len(document.lines),
162-
character=len(document.lines[-1])
163-
if document.lines
164-
else 0,
157+
character=len(document.lines[-1]) if document.lines else 0,
165158
),
166159
),
167160
new_text=new_text,
@@ -180,9 +173,7 @@ def goto_definition(
180173
self._ensure_context_for_document(params.text_document.uri)
181174
document = ls.workspace.get_document(params.text_document.uri)
182175
if self.lsp_context is None:
183-
raise RuntimeError(
184-
f"No context found for document: {document.path}"
185-
)
176+
raise RuntimeError(f"No context found for document: {document.path}")
186177

187178
references = get_model_definitions_for_a_path(
188179
self.lsp_context, params.text_document.uri
@@ -207,9 +198,7 @@ def goto_definition(
207198
]
208199

209200
except Exception as e:
210-
ls.show_message(
211-
f"Error getting references: {e}", types.MessageType.Error
212-
)
201+
ls.show_message(f"Error getting references: {e}", types.MessageType.Error)
213202
return []
214203

215204
def _context_get_or_load(self, document_uri: str) -> LSPContext:
@@ -284,9 +273,7 @@ def _diagnostics_to_lsp_diagnostics(
284273
) -> t.List[types.Diagnostic]:
285274
lsp_diagnostics: t.List[types.Diagnostic] = []
286275
for diagnostic in diagnostics:
287-
lsp_diagnostic = SQLMeshLanguageServer._diagnostic_to_lsp_diagnostic(
288-
diagnostic
289-
)
276+
lsp_diagnostic = SQLMeshLanguageServer._diagnostic_to_lsp_diagnostic(diagnostic)
290277
if lsp_diagnostic is not None:
291278
lsp_diagnostics.append(lsp_diagnostic)
292279
return lsp_diagnostics

vscode/extension/src/extension.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ import { AuthenticationProviderTobikoCloud } from './auth/auth'
1212
import { signOut } from './commands/signout'
1313
import { signIn } from './commands/signin'
1414
import { signInSpecifyFlow } from './commands/signinSpecifyFlow'
15-
<<<<<<< HEAD
1615
import { isErr } from '@bus/result'
17-
=======
18-
import { isErr } from '../../bus/src/result'
19-
>>>>>>> 7a972d4e (temp [ci skip])
2016
import {
2117
handleNotSginedInError,
2218
handleSqlmeshLspNotFoundError,

vscode/react/src/api/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export function useApiModelLineage(
7070
return useQuery({
7171
queryKey: ['/api/lineage', modelName],
7272
queryFn: async ({ signal }) => {
73-
console.log('use api model lineage', modelName)
7473
return await modelLineageApiLineageModelNameGet(modelName, { signal })
7574
},
7675
})

vscode/react/src/api/instance.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,17 @@ async function fetchAPIDevelopment<T = any, B extends object = any>(
5252
config: FetchOptions<B>,
5353
options?: Partial<FetchOptionsWithSignal>,
5454
): Promise<T & ResponseWithDetail> {
55-
console.log('fetchAPIDevelopment', config, options)
5655
// Generate a unique ID for this request
5756
// Create a promise that will resolve when we get a response with matching ID
5857
return new Promise((resolve, reject) => {
5958
const requestId = `query_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
6059
// Set up listener for the response
61-
console.log('setting up listener for response')
6260
const messageHandler = (event: MessageEvent) => {
63-
console.log('messageHandler in listener api development', event, 'checking requestId', requestId, 'versus', event.data.requestId)
6461
if (
6562
event.data &&
6663
event.data.key === 'query_response' &&
6764
event.data.requestId === requestId
6865
) {
69-
console.log('messageHandler in listener api development correct', event)
7066
// Remove the listener once we get our response
7167
window.removeEventListener('message', messageHandler)
7268

@@ -81,11 +77,9 @@ async function fetchAPIDevelopment<T = any, B extends object = any>(
8177

8278
// Add the listener
8379
window.addEventListener('message', messageHandler)
84-
console.log('added listener to window')
8580

8681
// If we're in an iframe, we need to post the message to the parent window
8782
if (window.parent !== window) {
88-
console.log('posting message to parent iframe')
8983
window.parent.postMessage({
9084
key: 'queryRequest',
9185
payload: {
@@ -136,16 +130,12 @@ export async function fetchAPIProduction<T = any, B extends object = any>(
136130
config: FetchOptions<B>,
137131
options?: Partial<FetchOptionsWithSignal>,
138132
): Promise<T & ResponseWithDetail> {
139-
console.log('fetchAPIProduction', config, options)
140-
141133
// Generate a unique ID for this request
142134
const requestId = `query_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
143135
// Create a promise that will resolve when we get a response with matching ID
144136
return new Promise((resolve, reject) => {
145137
// Set up listener for the response
146-
console.log('setting up listener for response')
147138
const messageHandler = (event: MessageEvent) => {
148-
console.log('messageHandler in listener api production', event)
149139
if (
150140
event.data &&
151141
event.data.key === 'query_response' &&
@@ -170,7 +160,6 @@ export async function fetchAPIProduction<T = any, B extends object = any>(
170160
// Send the message to VSCode with the query parameters and request ID
171161
// @ts-ignore
172162
const vscode = getVSCodeAPI()
173-
console.log('vscode to send message', vscode)
174163
vscode.postMessage({
175164
key: 'query_request',
176165
payload: {
@@ -180,7 +169,6 @@ export async function fetchAPIProduction<T = any, B extends object = any>(
180169
queryParams: config.params as any,
181170
},
182171
})
183-
console.log('sent message to vscode')
184172

185173
// Set a timeout to prevent hanging promises
186174
setTimeout(() => {

vscode/react/src/components/graph/ModelNode.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ export default function ModelNode({
9292
(e: React.MouseEvent) => {
9393
e.stopPropagation()
9494
if (handleClickModel) {
95-
console.log('handleClickModel', id)
96-
console.log('handleClickModel', models)
9795
handleClickModel(id)
9896
}
9997
},
@@ -149,8 +147,6 @@ export default function ModelNode({
149147
// isFalse(isModelUnknown)
150148
const shouldDisableColumns = isFalse(isModelSQL)
151149

152-
console.log('showcolumns', showColumns)
153-
154150
return (
155151
<div
156152
onMouseEnter={() => setIsMouseOver(true)}

vscode/react/src/components/graph/context.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export default function LineageFlowProvider({
143143
{},
144144
)
145145
const [withColumns, setWithColumns] = useState(showColumns)
146-
const [mainNode, setMainNode] = useState<string>()
146+
const [mainNode, setMainNode] = useState<string | undefined>()
147147
const [manuallySelectedColumn, setManuallySelectedColumn] =
148148
useState<[ModelSQLMeshModel, Column]>()
149149
const [activeEdges, setActiveEdges] = useState<ActiveEdges>(new Map())

vscode/react/src/pages/lineage.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,9 @@ export function LineagePage() {
5454

5555
function Lineage() {
5656
const { data: models, isLoading: isLoadingModels } = useApiModels()
57-
console.log('data', models, 'isLoadingModels', isLoadingModels)
5857
if (isLoadingModels || models === undefined) {
5958
return <div>Loading models...</div>
6059
}
61-
console.log('models', models)
6260
const modelsRecord = models.reduce(
6361
(acc, model) => {
6462
acc[model.name] = model
@@ -97,7 +95,6 @@ export function LineageComponentFromWeb({
9795
console.log(error)
9896
}
9997

100-
console.log('models inside', models)
10198
const model = models[selectedModel]
10299

103100
return (
@@ -118,18 +115,24 @@ export function LineageComponentFromWeb({
118115

119116
export function UpdateLineageFocus({ children }: { children: React.ReactNode }) {
120117
const lineageFlow = useLineageFlow()
121-
118+
122119
React.useEffect(() => {
123120
const handleMessage = (event: MessageEvent) => {
121+
console.log('handleMessage in lineage page', event)
124122
// Ensure the message is from VSCode
125123
if (event.data && event.data.key === 'vscode_send') {
126124
const payload = event.data.payload
127125
switch (payload.key) {
128126
case 'changeFocusOnFile':
129127
console.log('Changing focus to file:', payload.payload.path)
128+
lineageFlow.setMainNode('"memory"."sushi"."customers"')
129+
// Add a small delay to ensure the state update is processed
130+
setTimeout(() => {
131+
console.log('Delayed state update confirmation')
132+
}, 1000)
133+
console.log('set main node', lineageFlow.mainNode)
130134
// Implement your focus change logic here
131135
// TODO NEED TO PASS THE FQN of the model not the path
132-
lineageFlow.setMainNode(payload.payload.path)
133136
break
134137
default:
135138
console.error('Unhandled message type in lineage page:', payload.key)

vscode/react/src/style/variants.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,3 @@ export const EnumVariant = {
2121
} as const
2222

2323
export type Variant = (typeof EnumVariant)[keyof typeof EnumVariant]
24-
25-
26-
interface Model {
27-
test: string
28-
}
29-
30-
Model.do_something(model)
31-
const do_something = (model: Model) => {
32-
model.test = 'test'
33-
}
34-
35-
vscpde.postMessage()
36-
37-
class ModelClass {
38-
test: string
39-
40-
constructor(test: string) {
41-
this.test = test
42-
}
43-
44-
static do_something(model: Model) {
45-
model.test = 'test'
46-
}
47-
48-
do_something() {
49-
this.test = 'test'
50-
}
51-
}

0 commit comments

Comments
 (0)