@@ -15,9 +15,8 @@ import {
1515 RevealOutputChannelOn ,
1616} from 'vscode-languageclient/node' ;
1717
18- let client : LanguageClient ;
19- let outputChannel : OutputChannel ; // Trace channel
20- let serverOutputChannel : OutputChannel ; // Server logs channel (single instance)
18+ let client : LanguageClient | undefined ;
19+ let outputChannel : OutputChannel | undefined ; // Single output channel for server logs and trace
2120
2221function findNushellExecutable ( ) : string | null {
2322 try {
@@ -58,15 +57,15 @@ function startLanguageServer(
5857 ) ;
5958 return ;
6059 }
61- // Channel to receive detailed JSON-RPC trace between VS Code and the LSP server
60+ // Channel to receive both server logs and JSON-RPC trace between VS Code and the LSP server
6261 if ( outputChannel ) {
6362 try {
6463 outputChannel . dispose ( ) ;
6564 } catch {
6665 // ignore
6766 }
6867 }
69- outputChannel = window . createOutputChannel ( 'Nushell LSP Trace ' ) ;
68+ outputChannel = window . createOutputChannel ( 'Nushell Language Server ' ) ;
7069 context . subscriptions . push ( outputChannel ) ;
7170
7271 // Use Nushell's native LSP server
@@ -81,19 +80,13 @@ function startLanguageServer(
8180 } ,
8281 } ;
8382
84- // Ensure a single server output channel exists and is reused
85- if ( ! serverOutputChannel ) {
86- serverOutputChannel = window . createOutputChannel ( 'Nushell Language Server' ) ;
87- context . subscriptions . push ( serverOutputChannel ) ;
88- }
89-
9083 // Options to control the language client
9184 const clientOptions : LanguageClientOptions = {
92- // Route general server logs to a single, reusable channel
93- outputChannel : serverOutputChannel ,
85+ // Route general server logs to a single channel
86+ outputChannel : outputChannel ,
9487 // Never auto-reveal the server output channel
9588 revealOutputChannelOn : RevealOutputChannelOn . Never ,
96- // Send JSON-RPC trace to a dedicated channel visible in the Output panel
89+ // Send JSON-RPC trace to the same channel as server logs
9790 traceOutputChannel : outputChannel ,
9891 markdown : {
9992 isTrusted : true ,
@@ -103,7 +96,10 @@ function startLanguageServer(
10396 timeout : 10000 , // 10 seconds
10497 } ,
10598 // Register the server for nushell files
106- documentSelector : [ { scheme : 'file' , language : 'nushell' } ] ,
99+ documentSelector : [
100+ { scheme : 'file' , language : 'nushell' } ,
101+ { scheme : 'untitled' , language : 'nushell' } ,
102+ ] ,
107103 synchronize : {
108104 // Notify the server about file changes to nushell files
109105 fileEvents : vscode . workspace . createFileSystemWatcher ( '**/*.nu' ) ,
@@ -129,7 +125,7 @@ function startLanguageServer(
129125 messages : Trace . Messages ,
130126 verbose : Trace . Verbose ,
131127 } ;
132- client . setTrace ( map [ level ] ) ;
128+ client ? .setTrace ( map [ level ] ) ;
133129 try {
134130 outputChannel . appendLine ( `[Nushell] JSON-RPC tracing set to: ${ level } ` ) ;
135131 } catch {
@@ -173,8 +169,6 @@ function startLanguageServer(
173169}
174170
175171export function activate ( context : vscode . ExtensionContext ) {
176- console . log ( 'Terminals: ' + ( < any > vscode . window ) . terminals . length ) ;
177-
178172 // Find Nushell executable once and reuse it
179173 const found_nushell_path = findNushellExecutable ( ) ;
180174
@@ -185,31 +179,11 @@ export function activate(context: vscode.ExtensionContext) {
185179 ) : vscode . ProviderResult < vscode . TerminalProfile > {
186180 // Consume token to satisfy no-unused-vars without changing behavior
187181 void token ;
188- if ( found_nushell_path == null ) {
189- console . log (
190- 'Nushell not found in env: PATH or any of the heuristic locations .' ,
182+ if ( ! found_nushell_path ) {
183+ void vscode . window . showErrorMessage (
184+ 'Nushell executable not found in your PATH or configured location .' ,
191185 ) ;
192- // use an async arrow funciton to use `await` inside
193- return ( async ( ) => {
194- if (
195- ( await vscode . window . showErrorMessage (
196- 'We cannot find a nushell executable in your path or pre-defined locations' ,
197- 'install from website' ,
198- ) ) &&
199- ( await vscode . env . openExternal (
200- vscode . Uri . parse ( 'https://www.nushell.sh/' ) ,
201- ) ) &&
202- ( await vscode . window . showInformationMessage (
203- 'after you install nushell, you might need to reload vscode' ,
204- 'reload now' ,
205- ) )
206- ) {
207- vscode . commands . executeCommand ( 'workbench.action.reloadWindow' ) ;
208- }
209- // user has already seen error messages, but they didn't click through
210- // return a promise that never resolve to supress the confusing error
211- return await new Promise ( ( ) => undefined ) ;
212- } ) ( ) ;
186+ return undefined ;
213187 }
214188
215189 return {
@@ -272,6 +246,17 @@ export function activate(context: vscode.ExtensionContext) {
272246 ) ;
273247 context . subscriptions . push ( stopCommand ) ;
274248
249+ // Register a command to open documentation
250+ const openDocsCommand = vscode . commands . registerCommand (
251+ 'nushell.openDocs' ,
252+ async ( ) => {
253+ await vscode . env . openExternal (
254+ vscode . Uri . parse ( 'https://www.nushell.sh/book/' ) ,
255+ ) ;
256+ } ,
257+ ) ;
258+ context . subscriptions . push ( openDocsCommand ) ;
259+
275260 // Register a command to start the language server
276261 const startCommand = vscode . commands . registerCommand (
277262 'nushell.startLanguageServer' ,
0 commit comments