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
22 changes: 20 additions & 2 deletions crates/turborepo-lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,22 @@ impl LanguageServer for Backend {
});
}
Err(e) => {
self.client
.show_message(
MessageType::ERROR,
"Turborepo language server failed to connect to the daemon. See the \
output for details.",
)
.await;
self.client
.log_message(
MessageType::ERROR,
format!("failed to connect to daemon: {e}"),
)
.await;
return Err(Error::internal_error());
return Ok(InitializeResult {
..Default::default()
});
}
};

Expand All @@ -183,13 +192,22 @@ impl LanguageServer for Backend {
.await;
}
Err(e) => {
self.client
.show_message(
MessageType::ERROR,
"Turborepo language server failed to initialize. See the output for \
details.",
)
.await;
self.client
.log_message(
MessageType::ERROR,
format!("Failed to acquire pidlock: {e}"),
)
.await;
return Err(Error::internal_error());
return Ok(InitializeResult {
..Default::default()
});
}
}
}
Expand Down
58 changes: 34 additions & 24 deletions packages/turbo-vsc/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ export function activate(context: ExtensionContext) {
logs.appendLine(`using turbo at path ${turboPath}`);
}

const packagedLspPath = Uri.joinPath(
context.extensionUri,
"out",
`turborepo-lsp-${process.platform}-${process.arch}${
process.platform === "win32" ? ".exe" : ""
}`
).fsPath;

const installedTurboLspPath = findInstalledTurboLsp(
workspaceRoot,
syncOptions,
turboPath
);

const daemonCommandPath = installedTurboLspPath ?? packagedLspPath;

const getTurboPath = async () => {
turboPath ??= findTurbo(workspaceRoot, syncOptions);
if (turboPath) {
Expand All @@ -91,14 +107,22 @@ export function activate(context: ExtensionContext) {
return turboPath;
};

const getDaemonCommandPath = async () => {
if (fs.existsSync(daemonCommandPath)) {
return daemonCommandPath;
}

return getTurboPath();
};

context.subscriptions.push(
commands.registerCommand("turbo.daemon.start", async () => {
const turboPath = await getTurboPath();
if (!turboPath) {
const daemonPath = await getDaemonCommandPath();
if (!daemonPath) {
return;
}

cp.exec(`${quoteCommand(turboPath)} daemon start`, options, (err) => {
cp.exec(`${quoteCommand(daemonPath)} daemon start`, options, (err) => {
if (err) {
if (err.message.includes("command not found")) {
promptGlobalTurbo(useLocalTurbo);
Expand All @@ -115,12 +139,12 @@ export function activate(context: ExtensionContext) {

context.subscriptions.push(
commands.registerCommand("turbo.daemon.stop", async () => {
const turboPath = await getTurboPath();
if (!turboPath) {
const daemonPath = await getDaemonCommandPath();
if (!daemonPath) {
return;
}

cp.exec(`${quoteCommand(turboPath)} daemon stop`, options, (err) => {
cp.exec(`${quoteCommand(daemonPath)} daemon stop`, options, (err) => {
if (err) {
if (err.message.includes("command not found")) {
promptGlobalTurbo(useLocalTurbo);
Expand All @@ -137,12 +161,12 @@ export function activate(context: ExtensionContext) {

context.subscriptions.push(
commands.registerCommand("turbo.daemon.status", async () => {
const turboPath = await getTurboPath();
if (!turboPath) {
const daemonPath = await getDaemonCommandPath();
if (!daemonPath) {
return;
}

cp.exec(`${quoteCommand(turboPath)} daemon status`, options, (err) => {
cp.exec(`${quoteCommand(daemonPath)} daemon status`, options, (err) => {
if (err) {
if (err.message.includes("command not found")) {
promptGlobalTurbo(useLocalTurbo);
Expand Down Expand Up @@ -241,20 +265,6 @@ export function activate(context: ExtensionContext) {
// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used

const packagedLspPath = Uri.joinPath(
context.extensionUri,
"out",
`turborepo-lsp-${process.platform}-${process.arch}${
process.platform === "win32" ? ".exe" : ""
}`
).fsPath;

const installedTurboLspPath = findInstalledTurboLsp(
workspaceRoot,
syncOptions,
turboPath
);

if (!installedTurboLspPath && !fs.existsSync(packagedLspPath)) {
window.showInformationMessage(
`The turbo LSP is not yet supported on your platform (${process.platform}-${process.arch})`
Expand Down Expand Up @@ -363,7 +373,7 @@ function resolveTurboPath(

if (!fs.existsSync(resolvedPath)) {
logs.appendLine(
`manually specified turbo does not exist at path ${turboPath}`
`Manually specified turbo does not exist at path ${turboPath}`
);
return undefined;
}
Expand Down
Loading