Fix lints

This commit is contained in:
Lukas Wirth 2023-03-20 21:24:53 +01:00
parent 66636939a6
commit 3622fb6456
2 changed files with 37 additions and 42 deletions

View File

@ -121,52 +121,48 @@ export async function createClient(
const preview = config.previewRustcOutput; const preview = config.previewRustcOutput;
const errorCode = config.useRustcErrorCode; const errorCode = config.useRustcErrorCode;
diagnosticList.forEach((diag, idx) => { diagnosticList.forEach((diag, idx) => {
let value = const value =
typeof diag.code === "string" || typeof diag.code === "number" typeof diag.code === "string" || typeof diag.code === "number"
? diag.code ? diag.code
: diag.code?.value; : diag.code?.value;
if (value === "unlinked-file" && !unlinkedFiles.includes(uri)) { if (value === "unlinked-file" && !unlinkedFiles.includes(uri)) {
let config = vscode.workspace.getConfiguration("rust-analyzer"); const config = vscode.workspace.getConfiguration("rust-analyzer");
if (config.get("showUnlinkedFileNotification")) { if (config.get("showUnlinkedFileNotification")) {
unlinkedFiles.push(uri); unlinkedFiles.push(uri);
let folder = vscode.workspace.getWorkspaceFolder(uri)?.uri.fsPath; const folder = vscode.workspace.getWorkspaceFolder(uri)?.uri.fsPath;
if (folder) { if (folder) {
let parent_backslash = uri.fsPath.lastIndexOf( const parentBackslash = uri.fsPath.lastIndexOf(
pathSeparator + "src" pathSeparator + "src"
); );
let parent = uri.fsPath.substring(0, parent_backslash); const parent = uri.fsPath.substring(0, parentBackslash);
if (parent.startsWith(folder)) { if (parent.startsWith(folder)) {
let path = vscode.Uri.file( const path = vscode.Uri.file(
parent + pathSeparator + "Cargo.toml" parent + pathSeparator + "Cargo.toml"
); );
void vscode.workspace.fs.stat(path).then(() => { void vscode.workspace.fs.stat(path).then(async () => {
vscode.window const choice = await vscode.window.showInformationMessage(
.showInformationMessage(
`This rust file does not belong to a loaded cargo project. It looks like it might belong to the workspace at ${path}, do you want to add it to the linked Projects?`, `This rust file does not belong to a loaded cargo project. It looks like it might belong to the workspace at ${path}, do you want to add it to the linked Projects?`,
"Yes", "Yes",
"No", "No",
"Don't show this again" "Don't show this again"
) );
.then((choice) => {
switch (choice) { switch (choice) {
case "Yes": case "Yes":
break; break;
case "No": case "No":
config.update( await config.update(
"linkedProjects", "linkedProjects",
config config
.get<any[]>("linkedProjects") .get<any[]>("linkedProjects")
?.concat( ?.concat(
path.fsPath.substring( path.fsPath.substring(folder.length)
folder!.length
)
), ),
false false
); );
break; break;
case "Don't show this again": case "Don't show this again":
config.update( await config.update(
"showUnlinkedFileNotification", "showUnlinkedFileNotification",
false, false,
false false
@ -174,7 +170,6 @@ export async function createClient(
break; break;
} }
}); });
});
} }
} }
} }

View File

@ -95,7 +95,6 @@ export class Ctx {
) { ) {
extCtx.subscriptions.push(this); extCtx.subscriptions.push(this);
this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left); this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
this.statusBar.show();
this.workspace = workspace; this.workspace = workspace;
this.clientSubscriptions = []; this.clientSubscriptions = [];
this.commandDisposables = []; this.commandDisposables = [];
@ -338,6 +337,7 @@ export class Ctx {
setServerStatus(status: ServerStatusParams | { health: "stopped" }) { setServerStatus(status: ServerStatusParams | { health: "stopped" }) {
let icon = ""; let icon = "";
const statusBar = this.statusBar; const statusBar = this.statusBar;
statusBar.show();
statusBar.tooltip = new vscode.MarkdownString("", true); statusBar.tooltip = new vscode.MarkdownString("", true);
statusBar.tooltip.isTrusted = true; statusBar.tooltip.isTrusted = true;
switch (status.health) { switch (status.health) {
@ -386,7 +386,7 @@ export class Ctx {
); );
statusBar.tooltip.appendMarkdown("\n\n[Open logs](command:rust-analyzer.openLogs)"); statusBar.tooltip.appendMarkdown("\n\n[Open logs](command:rust-analyzer.openLogs)");
statusBar.tooltip.appendMarkdown("\n\n[Restart server](command:rust-analyzer.startServer)"); statusBar.tooltip.appendMarkdown("\n\n[Restart server](command:rust-analyzer.startServer)");
statusBar.tooltip.appendMarkdown("[Stop server](command:rust-analyzer.stopServer)"); statusBar.tooltip.appendMarkdown("\n\n[Stop server](command:rust-analyzer.stopServer)");
if (!status.quiescent) icon = "$(sync~spin) "; if (!status.quiescent) icon = "$(sync~spin) ";
statusBar.text = `${icon}rust-analyzer`; statusBar.text = `${icon}rust-analyzer`;
} }