Skip to content

Commit 79ebad9

Browse files
committed
progress [ci skip]
1 parent 926bfa0 commit 79ebad9

5 files changed

Lines changed: 29 additions & 226 deletions

File tree

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vscode/extension/src/extension.ts

Lines changed: 14 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<<<<<<< HEAD
21
import { format } from "./commands/format"
32
import * as vscode from "vscode"
43
import {
@@ -19,8 +18,11 @@ import { signIn } from "./commands/signin"
1918
import { signInSpecifyFlow } from "./commands/signinSpecifyFlow"
2019
import { isErr } from "./utilities/functional/result"
2120
import { handleNotSginedInError } from "./utilities/errors"
21+
import { WebServer } from "./web-server/server"
22+
import { LineagePanel } from "./webviews/lineagePanel"
2223

2324
let lspClient: LSPClient | undefined
25+
let webServer: WebServer | undefined;
2426

2527
// This method is called when your extension is activated
2628
// Your extension is activated the very first time the command is executed
@@ -59,6 +61,17 @@ export async function activate(context: vscode.ExtensionContext) {
5961
context.subscriptions.push(
6062
vscode.commands.registerCommand("sqlmesh.format", format(authProvider))
6163
)
64+
// Register the webview
65+
const lineagePanel = new LineagePanel(
66+
context.extensionUri,
67+
() => webServer?.url ?? ""
68+
);
69+
context.subscriptions.push(
70+
vscode.window.registerWebviewViewProvider(
71+
LineagePanel.viewType,
72+
lineagePanel
73+
)
74+
);
6275

6376
lspClient = new LSPClient()
6477
const result = await lspClient.start()
@@ -97,214 +110,7 @@ export async function deactivate() {
97110
if (lspClient) {
98111
await lspClient.dispose()
99112
}
100-
}
101-
=======
102-
// The module 'vscode' contains the VS Code extensibility API
103-
// Import the module and reference it with the alias vscode in your code below
104-
import * as vscode from "vscode";
105-
import { actual_callout } from "./services";
106-
import {
107-
createOutputChannel,
108-
onDidChangeConfiguration,
109-
registerCommand,
110-
} from "./common/vscodeapi";
111-
import {
112-
registerLogger,
113-
traceError,
114-
traceInfo,
115-
traceLog,
116-
traceVerbose,
117-
} from "./common/log";
118-
import {
119-
checkVersion,
120-
getInterpreterDetails,
121-
onDidChangePythonInterpreter,
122-
resolveInterpreter,
123-
} from "./common/python";
124-
import { restartServer } from "./common/server";
125-
import { LanguageClient } from "vscode-languageclient/lib/node/main";
126-
import { getLSClientTraceLevel } from "./common/utilities";
127-
import { loadServerDefaults } from "./common/setup";
128-
import { checkIfConfigurationChanged } from "./common/settings";
129-
import { getInterpreterFromSetting } from "./common/settings";
130-
import { startWebServer, WebServer } from "./web-server/server";
131-
import { isErr } from "./functional/result";
132-
import { LineagePanel } from "./webviews/lineagePanel";
133-
import { activateLsp, deactivateLsp } from "./lsp/lsp";
134-
135-
let lsClient: LanguageClient | undefined;
136-
let webServer: WebServer | undefined;
137-
138-
// This method is called when your extension is activated
139-
// Your extension is activated the very first time the command is executed
140-
export async function activate(context: vscode.ExtensionContext) {
141-
const extensionOutputChannel = createOutputChannel("sqlmesh");
142-
context.subscriptions.push(
143-
extensionOutputChannel,
144-
registerLogger(extensionOutputChannel)
145-
);
146-
const lspOutputChannel = createOutputChannel("sqlmesh-lsp");
147-
context.subscriptions.push(
148-
lspOutputChannel,
149-
registerLogger(lspOutputChannel)
150-
);
151-
const serverOutputChannel = createOutputChannel("sqlmesh-server");
152-
context.subscriptions.push(
153-
serverOutputChannel,
154-
registerLogger(serverOutputChannel)
155-
);
156-
157-
traceInfo("Activating extension");
158-
159-
const changeLogLevel = async (c: vscode.LogLevel, g: vscode.LogLevel) => {
160-
const level = getLSClientTraceLevel(c, g);
161-
await lsClient?.setTrace(level);
162-
};
163-
164-
context.subscriptions.push(
165-
lspOutputChannel.onDidChangeLogLevel(async (e) => {
166-
await changeLogLevel(e, vscode.env.logLevel);
167-
}),
168-
vscode.env.onDidChangeLogLevel(async (e) => {
169-
await changeLogLevel(lspOutputChannel.logLevel, e);
170-
})
171-
);
172-
173-
// The command has been defined in the package.json file
174-
// Now provide the implementation of the command with registerCommand
175-
// The commandId parameter must match the command field in package.json
176-
const disposable = vscode.commands.registerCommand(
177-
"sqlmesh.format",
178-
async () => {
179-
const out = await actual_callout.format();
180-
if (out === 0) {
181-
vscode.window.showInformationMessage("Project formatted successfully");
182-
} else {
183-
vscode.window.showErrorMessage("Project format failed");
184-
}
185-
}
186-
);
187-
188-
context.subscriptions.push(disposable);
189-
190-
const serverInfo = loadServerDefaults();
191-
const serverName = serverInfo.name;
192-
const serverId = serverInfo.module;
193-
194-
// Log Server information
195-
traceLog(`Name: ${serverInfo.name}`);
196-
traceLog(`Module: ${serverInfo.module}`);
197-
traceVerbose(`Full Server Info: ${JSON.stringify(serverInfo)}`);
198-
199-
const runServer = async () => {
200-
const interpreter = getInterpreterFromSetting(serverId);
201-
if (interpreter && interpreter.length > 0) {
202-
if (checkVersion(await resolveInterpreter(interpreter))) {
203-
traceVerbose(
204-
`Using interpreter from ${serverInfo.module}.interpreter: ${interpreter.join(" ")}`
205-
);
206-
lsClient = await restartServer(
207-
serverId,
208-
serverName,
209-
lspOutputChannel,
210-
lsClient
211-
);
212-
}
213-
return;
214-
}
215-
216-
const interpreterDetails = await getInterpreterDetails();
217-
if (interpreterDetails.path) {
218-
traceVerbose(
219-
`Using interpreter from Python extension: ${interpreterDetails.path.join(" ")}`
220-
);
221-
lsClient = await restartServer(
222-
serverId,
223-
serverName,
224-
lspOutputChannel,
225-
lsClient
226-
);
227-
return;
228-
}
229-
230-
traceError(
231-
"Python interpreter missing:\r\n" +
232-
"[Option 1] Select python interpreter using the ms-python.python.\r\n" +
233-
`[Option 2] Set an interpreter using "${serverId}.interpreter" setting.\r\n` +
234-
"Please use Python 3.8 or greater."
235-
);
236-
};
237-
238-
context.subscriptions.push(
239-
onDidChangePythonInterpreter(async () => {
240-
await runServer();
241-
await restartUIServer(serverOutputChannel);
242-
}),
243-
onDidChangeConfiguration(async (e: vscode.ConfigurationChangeEvent) => {
244-
if (checkIfConfigurationChanged(e, serverId)) {
245-
await restartUIServer(serverOutputChannel);
246-
await restartServer(serverId, serverName, lspOutputChannel, lsClient);
247-
}
248-
}),
249-
registerCommand(`${serverId}.restart`, async () => {
250-
await runServer();
251-
await restartUIServer(serverOutputChannel);
252-
})
253-
);
254-
255-
startServer(serverOutputChannel);
256-
257-
// Register the webview
258-
const lineagePanel = new LineagePanel(
259-
context.extensionUri,
260-
() => webServer?.url ?? ""
261-
);
262-
context.subscriptions.push(
263-
vscode.window.registerWebviewViewProvider(
264-
LineagePanel.viewType,
265-
lineagePanel
266-
)
267-
);
268-
269-
const interpreterDetails = await getInterpreterDetails();
270-
if (interpreterDetails.path) {
271-
traceLog(
272-
`Using interpreter from Python extension: ${interpreterDetails.path.join(" ")}`
273-
);
274-
}
275-
276-
await activateLsp(context);
277-
traceInfo("Extension activated");
278-
}
279-
280-
export async function startServer(
281-
serverOutputChannel: vscode.LogOutputChannel
282-
): Promise<WebServer> {
283-
if (webServer) {
284-
return webServer;
285-
}
286-
const result = await startWebServer(serverOutputChannel);
287-
if (isErr(result)) {
288-
throw new Error(result.error);
289-
}
290-
webServer = result.value;
291-
return webServer;
292-
}
293-
294-
export async function restartUIServer(
295-
serverOutputChannel: vscode.LogOutputChannel
296-
) {
297-
if (webServer) {
298-
webServer.stop();
299-
}
300-
await startServer(serverOutputChannel);
301-
}
302-
303-
// This method is called when your extension is deactivated
304-
export async function deactivate() {
305113
if (webServer) {
306114
webServer.stop();
307115
}
308-
await deactivateLsp();
309116
}
310-

vscode/extension/src/web-server/server.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { ChildProcess, spawn } from "child_process"
2-
import { isErr, ok, Result } from "../functional/result"
3-
import getPort from "../get-port"
4-
import { sqlmesh_exec } from "../sqlmesh/sqlmesh"
2+
import { isErr, ok, Result } from "../utilities/functional/result"
3+
import { sqlmesh_exec } from "../utilities/sqlmesh/sqlmesh"
54
import * as vscode from 'vscode'
6-
import { isProduction } from "../is_dev"
5+
import { isProduction } from "../utilities/isDev"
6+
import getPort from "../utilities/getPort"
7+
import { ErrorType } from "../utilities/errors"
78

89
export interface Server {
910
port: number;
1011
url: string;
1112
stop: () => void;
1213
}
1314

14-
export const startWebServer = async (outputChannel: vscode.OutputChannel): Promise<Result<WebServer, string>> => {
15+
export const startWebServer = async (outputChannel: vscode.OutputChannel): Promise<Result<WebServer, ErrorType>> => {
1516
const sqlmesh = await sqlmesh_exec()
1617
if (isErr(sqlmesh)) {
1718
return sqlmesh

vscode/extension/src/webviews/lineagePanel.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1+
import { CallbackEvent } from "../../bus/src/callbacks";
12
import {
23
CancellationToken,
3-
commands,
44
Disposable,
5-
TextEditor,
65
Uri,
76
WebviewView,
87
WebviewViewProvider,
98
WebviewViewResolveContext,
109
window,
1110
workspace,
1211
} from "vscode";
13-
import { isProduction } from "../is_dev";
14-
import { type CallbackEvent } from "@bus/callbacks";
15-
import { getWorkspaceFolders } from "../common/vscodeapi";
12+
import { isProduction } from "../utilities/isDev";
13+
import { getWorkspaceFolders } from "../utilities/common/vscodeapi";
1614

1715
export class LineagePanel implements WebviewViewProvider, Disposable {
1816
public static readonly viewType = "sqlmesh.lineage";
@@ -24,7 +22,7 @@ export class LineagePanel implements WebviewViewProvider, Disposable {
2422
public constructor(extensionUri: Uri, getServerUrl: () => string) {
2523
this._extensionUri = extensionUri;
2624
this.getServerUrl = getServerUrl;
27-
window.onDidChangeActiveTextEditor((event: TextEditor | undefined) => {
25+
window.onDidChangeActiveTextEditor(() => {
2826
if (this.panel) {
2927
const { externalUrl, externalAuthority } =
3028
this.externalUrlAndAutority();
@@ -33,10 +31,6 @@ export class LineagePanel implements WebviewViewProvider, Disposable {
3331
});
3432
}
3533

36-
private getPanel() {
37-
return this.panel;
38-
}
39-
4034
public resolveWebviewView(
4135
webviewView: WebviewView,
4236
_context: WebviewViewResolveContext,

vscode/extension/tsconfig.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"module": "Node16",
3+
"module": "NodeNext",
44
"target": "ES2022",
55
"lib": [
66
"ES2022",
@@ -14,15 +14,16 @@
1414
"noFallthroughCasesInSwitch": true,
1515
"noUnusedParameters": true,
1616
"noUnusedLocals": true,
17+
"types": ["mocha"],
1718
"paths": {
18-
"@bus/*": ["../bus/src/*"]
19+
"@bus/*": ["../../bus/src/*"]
1920
}
2021
},
2122
"include": [
2223
"src/**/*",
2324
"../bus/src/**/*"
2425
],
2526
"exclude": [
26-
"node_modules", "../node_modules"
27+
"node_modules", "../node_modules", "../../node_modules"
2728
]
2829
}

0 commit comments

Comments
 (0)