1+ import * as fs from 'fs' ;
12import * as vscode from 'vscode' ;
23import { CancellationError } from 'vscode' ;
34import { inject , injectable } from 'inversify' ;
@@ -381,12 +382,20 @@ export class DeepnoteLspClientManager
381382 logger . info ( `Starting SQL LSP with ${ connections . length } database connection(s)` ) ;
382383
383384 // Use IPC transport - must match the server's hardcoded 'node-ipc' method
385+ // Set NODE_PATH to include the sql-lsp-modules directory for runtime dependencies
386+ const sqlLspModulesPath = this . getSqlLspModulesPath ( ) ;
387+ const nodePathEnv = sqlLspModulesPath ? { NODE_PATH : sqlLspModulesPath } : { } ;
388+
384389 const serverOptions : ServerOptions = {
385- run : { module : serverModule , transport : TransportKind . ipc } ,
390+ run : {
391+ module : serverModule ,
392+ transport : TransportKind . ipc ,
393+ options : { env : { ...process . env , ...nodePathEnv } }
394+ } ,
386395 debug : {
387396 module : serverModule ,
388397 transport : TransportKind . ipc ,
389- options : { execArgv : [ '--nolazy' , '--inspect=6009' ] }
398+ options : { execArgv : [ '--nolazy' , '--inspect=6009' ] , env : { ... process . env , ... nodePathEnv } }
390399 }
391400 } ;
392401
@@ -532,7 +541,7 @@ export class DeepnoteLspClientManager
532541 * @returns Path to the vscodeExtensionServer.js module for IPC transport
533542 */
534543 private getSqlLanguageServerModule ( ) : string {
535- // Try require.resolve first - this handles different package layouts
544+ // Try require.resolve first - this handles different package layouts (works in dev mode)
536545 try {
537546 const serverModule = require . resolve ( '@deepnote/sql-language-server/dist/bin/vscodeExtensionServer.js' ) ;
538547
@@ -543,7 +552,8 @@ export class DeepnoteLspClientManager
543552 logger . trace ( 'require.resolve failed, falling back to path construction:' , error ) ;
544553 }
545554
546- // Fallback: use extension path construction
555+ // Fallback: use extension path construction (works in packaged extension)
556+ // The sql-language-server is bundled into dist/sqlLanguageServer.cjs during build
547557 let extensionPath = vscode . extensions . getExtension ( 'Deepnote.vscode-deepnote' ) ?. extensionPath ;
548558
549559 if ( ! extensionPath ) {
@@ -552,20 +562,33 @@ export class DeepnoteLspClientManager
552562 logger . trace ( 'Using __dirname to find extension path:' , extensionPath ) ;
553563 }
554564
555- const serverModule = path . join (
556- extensionPath ,
557- 'node_modules' ,
558- '@deepnote' ,
559- 'sql-language-server' ,
560- 'dist' ,
561- 'bin' ,
562- 'vscodeExtensionServer.js'
563- ) ;
565+ const serverModule = path . join ( extensionPath , 'dist' , 'sqlLanguageServer.cjs' ) ;
564566 logger . trace ( 'SQL LSP server module (fallback):' , serverModule ) ;
565567
566568 return serverModule ;
567569 }
568570
571+ /**
572+ * Get the path to the sql-lsp-modules directory containing runtime dependencies
573+ * @returns Path to the node_modules directory for SQL LSP, or undefined if not found
574+ */
575+ private getSqlLspModulesPath ( ) : string | undefined {
576+ let extensionPath = vscode . extensions . getExtension ( 'Deepnote.vscode-deepnote' ) ?. extensionPath ;
577+
578+ if ( ! extensionPath ) {
579+ extensionPath = path . join ( __dirname , '..' , '..' , '..' ) ;
580+ }
581+
582+ const modulesPath = path . join ( extensionPath , 'dist' , 'sql-lsp-modules' , 'node_modules' ) ;
583+
584+ // Return undefined if the directory doesn't exist
585+ if ( ! fs . existsSync ( modulesPath ) ) {
586+ return undefined ;
587+ }
588+
589+ return modulesPath ;
590+ }
591+
569592 /**
570593 * Get SQL connections configuration from integration storage for the current project.
571594 * Only returns integrations that are configured for the specific project.
0 commit comments