Skip to content

Commit

Permalink
Write proc-macro server spawn errors to the status text
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Jul 30, 2023
1 parent f442c4a commit ef85eaa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
5 changes: 5 additions & 0 deletions crates/rust-analyzer/src/reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ impl GlobalState {
if self.proc_macro_clients.iter().any(|it| it.is_err()) {
status.health = lsp_ext::Health::Warning;
message.push_str("Failed to spawn one or more proc-macro servers.\n\n");
for err in self.proc_macro_clients.iter() {
if let Err(err) = err {
format_to!(message, "- {err}\n");
}
}
}
if !self.config.cargo_autoreload()
&& self.is_quiescent()
Expand Down
36 changes: 18 additions & 18 deletions editors/code/src/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export type Workspace =

export function fetchWorkspace(): Workspace {
const folders = (vscode.workspace.workspaceFolders || []).filter(
(folder) => folder.uri.scheme === "file",
(folder) => folder.uri.scheme === "file"
);
const rustDocuments = vscode.workspace.textDocuments.filter((document) =>
isRustDocument(document),
isRustDocument(document)
);

return folders.length === 0
Expand All @@ -61,7 +61,7 @@ export function fetchWorkspace(): Workspace {
export async function discoverWorkspace(
files: readonly vscode.TextDocument[],
command: string[],
options: ExecOptions,
options: ExecOptions
): Promise<JsonProject> {
const paths = files.map((f) => `"${f.uri.fsPath}"`).join(" ");
const joinedCommand = command.join(" ");
Expand Down Expand Up @@ -110,7 +110,7 @@ export class Ctx {
constructor(
readonly extCtx: vscode.ExtensionContext,
commandFactories: Record<string, CommandFactory>,
workspace: Workspace,
workspace: Workspace
) {
extCtx.subscriptions.push(this);
this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
Expand Down Expand Up @@ -186,7 +186,7 @@ export class Ctx {

log.error("Bootstrap error", err);
throw new Error(message);
},
}
);
const newEnv = Object.assign({}, process.env, this.config.serverExtraEnv);
const run: lc.Executable = {
Expand Down Expand Up @@ -216,7 +216,7 @@ export class Ctx {
return discoverWorkspace([file], discoverProjectCommand, {
cwd: path.dirname(file.uri.fsPath),
});
}),
})
);

this.addToDiscoveredWorkspaces(workspaces);
Expand All @@ -230,7 +230,7 @@ export class Ctx {
if (key === "linkedProjects" && this.config.discoveredWorkspaces.length > 0) {
obj["linkedProjects"] = this.config.discoveredWorkspaces;
}
},
}
);

this._client = await createClient(
Expand All @@ -239,17 +239,17 @@ export class Ctx {
initializationOptions,
serverOptions,
this.config,
this.unlinkedFiles,
this.unlinkedFiles
);
this.pushClientCleanup(
this._client.onNotification(ra.serverStatus, (params) =>
this.setServerStatus(params),
),
this.setServerStatus(params)
)
);
this.pushClientCleanup(
this._client.onNotification(ra.openServerLogs, () => {
this.outputChannel!.show();
}),
})
);
}
return this._client;
Expand Down Expand Up @@ -395,7 +395,7 @@ export class Ctx {
} else {
callback = () =>
vscode.window.showErrorMessage(
`command ${fullName} failed: rust-analyzer server is not running`,
`command ${fullName} failed: rust-analyzer server is not running`
);
}

Expand Down Expand Up @@ -423,7 +423,7 @@ export class Ctx {
}
statusBar.color = new vscode.ThemeColor("statusBarItem.warningForeground");
statusBar.backgroundColor = new vscode.ThemeColor(
"statusBarItem.warningBackground",
"statusBarItem.warningBackground"
);
statusBar.command = "rust-analyzer.openLogs";
icon = "$(warning) ";
Expand All @@ -440,7 +440,7 @@ export class Ctx {
case "stopped":
statusBar.tooltip.appendText("Server is stopped");
statusBar.tooltip.appendMarkdown(
"\n\n[Start server](command:rust-analyzer.startServer)",
"\n\n[Start server](command:rust-analyzer.startServer)"
);
statusBar.color = undefined;
statusBar.backgroundColor = undefined;
Expand All @@ -449,17 +449,17 @@ export class Ctx {
return;
}
if (statusBar.tooltip.value) {
statusBar.tooltip.appendText("\n\n");
statusBar.tooltip.appendMarkdown("\n\n---\n\n");
}
statusBar.tooltip.appendMarkdown("\n\n[Open logs](command:rust-analyzer.openLogs)");
statusBar.tooltip.appendMarkdown(
"\n\n[Reload Workspace](command:rust-analyzer.reloadWorkspace)",
"\n\n[Reload Workspace](command:rust-analyzer.reloadWorkspace)"
);
statusBar.tooltip.appendMarkdown(
"\n\n[Rebuild Proc Macros](command:rust-analyzer.rebuildProcMacros)",
"\n\n[Rebuild Proc Macros](command:rust-analyzer.rebuildProcMacros)"
);
statusBar.tooltip.appendMarkdown(
"\n\n[Restart server](command:rust-analyzer.restartServer)",
"\n\n[Restart server](command:rust-analyzer.restartServer)"
);
statusBar.tooltip.appendMarkdown("\n\n[Stop server](command:rust-analyzer.stopServer)");
if (!status.quiescent) icon = "$(sync~spin) ";
Expand Down

0 comments on commit ef85eaa

Please sign in to comment.