Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
346 changes: 175 additions & 171 deletions CHANGELOG.md

Large diffs are not rendered by default.

63 changes: 39 additions & 24 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
},
"dependencies": {
"vscode-languageclient": "9.0.1",
"which": "5.0.0"
"which": "6.0.1"
},
"devDependencies": {
"@types/vscode": "1.103.0",
"@types/vscode": "1.110.0",
"@types/which": "3.0.4",
"@vscode/test-electron": "2.5.2"
}
}
69 changes: 27 additions & 42 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import {
RevealOutputChannelOn,
} from 'vscode-languageclient/node';

let client: LanguageClient;
let outputChannel: OutputChannel; // Trace channel
let serverOutputChannel: OutputChannel; // Server logs channel (single instance)
let client: LanguageClient | undefined;
let outputChannel: OutputChannel | undefined; // Single output channel for server logs and trace

function findNushellExecutable(): string | null {
try {
Expand Down Expand Up @@ -58,15 +57,15 @@ function startLanguageServer(
);
return;
}
// Channel to receive detailed JSON-RPC trace between VS Code and the LSP server
// Channel to receive both server logs and JSON-RPC trace between VS Code and the LSP server
if (outputChannel) {
try {
outputChannel.dispose();
} catch {
// ignore
}
}
outputChannel = window.createOutputChannel('Nushell LSP Trace');
outputChannel = window.createOutputChannel('Nushell Language Server');
context.subscriptions.push(outputChannel);

// Use Nushell's native LSP server
Expand All @@ -81,19 +80,13 @@ function startLanguageServer(
},
};

// Ensure a single server output channel exists and is reused
if (!serverOutputChannel) {
serverOutputChannel = window.createOutputChannel('Nushell Language Server');
context.subscriptions.push(serverOutputChannel);
}

// Options to control the language client
const clientOptions: LanguageClientOptions = {
// Route general server logs to a single, reusable channel
outputChannel: serverOutputChannel,
// Route general server logs to a single channel
outputChannel: outputChannel,
// Never auto-reveal the server output channel
revealOutputChannelOn: RevealOutputChannelOn.Never,
// Send JSON-RPC trace to a dedicated channel visible in the Output panel
// Send JSON-RPC trace to the same channel as server logs
traceOutputChannel: outputChannel,
markdown: {
isTrusted: true,
Expand All @@ -103,7 +96,10 @@ function startLanguageServer(
timeout: 10000, // 10 seconds
},
// Register the server for nushell files
documentSelector: [{ scheme: 'file', language: 'nushell' }],
documentSelector: [
{ scheme: 'file', language: 'nushell' },
{ scheme: 'untitled', language: 'nushell' },
],
synchronize: {
// Notify the server about file changes to nushell files
fileEvents: vscode.workspace.createFileSystemWatcher('**/*.nu'),
Expand All @@ -129,7 +125,7 @@ function startLanguageServer(
messages: Trace.Messages,
verbose: Trace.Verbose,
};
client.setTrace(map[level]);
client?.setTrace(map[level]);
try {
outputChannel.appendLine(`[Nushell] JSON-RPC tracing set to: ${level}`);
} catch {
Expand Down Expand Up @@ -173,8 +169,6 @@ function startLanguageServer(
}

export function activate(context: vscode.ExtensionContext) {
console.log('Terminals: ' + (<any>vscode.window).terminals.length);

// Find Nushell executable once and reuse it
const found_nushell_path = findNushellExecutable();

Expand All @@ -185,31 +179,11 @@ export function activate(context: vscode.ExtensionContext) {
): vscode.ProviderResult<vscode.TerminalProfile> {
// Consume token to satisfy no-unused-vars without changing behavior
void token;
if (found_nushell_path == null) {
console.log(
'Nushell not found in env:PATH or any of the heuristic locations.',
if (!found_nushell_path) {
void vscode.window.showErrorMessage(
'Nushell executable not found in your PATH or configured location.',
);
// use an async arrow funciton to use `await` inside
return (async () => {
if (
(await vscode.window.showErrorMessage(
'We cannot find a nushell executable in your path or pre-defined locations',
'install from website',
)) &&
(await vscode.env.openExternal(
vscode.Uri.parse('https://www.nushell.sh/'),
)) &&
(await vscode.window.showInformationMessage(
'after you install nushell, you might need to reload vscode',
'reload now',
))
) {
vscode.commands.executeCommand('workbench.action.reloadWindow');
}
// user has already seen error messages, but they didn't click through
// return a promise that never resolve to supress the confusing error
return await new Promise(() => undefined);
})();
return undefined;
}

return {
Expand Down Expand Up @@ -272,6 +246,17 @@ export function activate(context: vscode.ExtensionContext) {
);
context.subscriptions.push(stopCommand);

// Register a command to open documentation
const openDocsCommand = vscode.commands.registerCommand(
'nushell.openDocs',
async () => {
await vscode.env.openExternal(
vscode.Uri.parse('https://www.nushell.sh/book/'),
);
},
);
context.subscriptions.push(openDocsCommand);

// Register a command to start the language server
const startCommand = vscode.commands.registerCommand(
'nushell.startLanguageServer',
Expand Down
15 changes: 15 additions & 0 deletions client/src/types/which.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
declare module 'which' {
interface Options {
nothrow?: boolean;
path?: string;
env?: string;
}

function whichSync(command: string, options?: Options): string | null;

namespace whichSync {
function sync(command: string, options?: Options): string | null;
}

export = whichSync;
}
Loading
Loading