1- < < < << << HEAD
21import { format } from "./commands/format"
32import * as vscode from "vscode"
43import {
@@ -19,8 +18,11 @@ import { signIn } from "./commands/signin"
1918import { signInSpecifyFlow } from "./commands/signinSpecifyFlow"
2019import { isErr } from "./utilities/functional/result"
2120import { handleNotSginedInError } from "./utilities/errors"
21+ import { WebServer } from "./web-server/server"
22+ import { LineagePanel } from "./webviews/lineagePanel"
2223
2324let 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-
0 commit comments