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
4 changes: 2 additions & 2 deletions client/package-lock.json

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

131 changes: 95 additions & 36 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,63 @@ function findNushellExecutable(): string | null {
}
}

function startLanguageServer(
context: vscode.ExtensionContext,
found_nushell_path: string,
): void {
// Use Nushell's native LSP server
const serverOptions: ServerOptions = {
run: {
command: found_nushell_path,
args: ['--lsp'],
},
debug: {
command: found_nushell_path,
args: ['--lsp'],
},
};

// Options to control the language client
const clientOptions: LanguageClientOptions = {
initializationOptions: {
timeout: 10000, // 10 seconds
},
// Register the server for nushell files
documentSelector: [{ scheme: 'file', language: 'nushell' }],
synchronize: {
// Notify the server about file changes to nushell files
fileEvents: vscode.workspace.createFileSystemWatcher('**/*.nu'),
},
};

// Create the language client and start the client.
client = new LanguageClient(
'nushellLanguageServer',
'Nushell Language Server',
serverOptions,
clientOptions,
);

// Start the language client and register a disposable that stops it when disposed
client.start().catch((error) => {
vscode.window.showErrorMessage(
`Failed to start Nushell language server: ${error.message}`,
);
});

const disposable = new vscode.Disposable(() => {
if (client) {
client.stop().catch((error) => {
console.error(
'Failed to stop Nushell Language Server on dispose:',
error,
);
});
}
});
context.subscriptions.push(disposable);
}

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

Expand Down Expand Up @@ -111,45 +168,47 @@ export function activate(context: vscode.ExtensionContext) {
return;
}

// Use Nushell's native LSP server
const serverOptions: ServerOptions = {
run: {
command: found_nushell_path,
args: ['--lsp'],
},
debug: {
command: found_nushell_path,
args: ['--lsp'],
},
};

// Options to control the language client
const clientOptions: LanguageClientOptions = {
initializationOptions: {
timeout: 10000, // 10 seconds
// Start the language server when the extension is activated
startLanguageServer(context, found_nushell_path);

// Register a command to stop the language server
const stopCommand = vscode.commands.registerCommand(
'nushell.stopLanguageServer',
async () => {
if (client) {
try {
await client.stop();
client = undefined;
vscode.window.showInformationMessage(
'Nushell Language Server stopped.',
);
} catch (error) {
vscode.window.showErrorMessage(
`Failed to stop Nushell Language Server: ${error}`,
);
}
} else {
vscode.window.showInformationMessage(
'Nushell Language Server is not running.',
);
}
},
// Register the server for nushell files
documentSelector: [{ scheme: 'file', language: 'nushell' }],
synchronize: {
// Notify the server about file changes to nushell files
fileEvents: vscode.workspace.createFileSystemWatcher('**/*.nu'),
);
context.subscriptions.push(stopCommand);

// Register a command to start the language server
const startCommand = vscode.commands.registerCommand(
'nushell.startLanguageServer',
() => {
startLanguageServer(context, found_nushell_path);
if (client) {
vscode.window.showInformationMessage(
'Nushell Language Server started.',
);
}
},
};

// Create the language client and start the client.
client = new LanguageClient(
'nushellLanguageServer',
'Nushell Language Server',
serverOptions,
clientOptions,
);

// Start the client. This will also launch the server
client.start().catch((error) => {
vscode.window.showErrorMessage(
`Failed to start Nushell language server: ${error.message}`,
);
});
context.subscriptions.push(startCommand);
}

export function deactivate(): Thenable<void> | undefined {
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

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

12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,17 @@
"scope": "window"
}
}
}
},
"commands": [
{
"command": "nushell.stopLanguageServer",
"title": "Nushell: Stop Language Server"
},
{
"command": "nushell.startLanguageServer",
"title": "Nushell: Start Language Server"
}
]
},
"scripts": {
"vscode:prepublish": "npm run lint && npm run compile",
Expand Down