mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
7591: Fix/no floating promises r=matklad a=sahandevs closes #3515 - added `@typescript-eslint/no-floating-promises: error` rule - changed `"no-console": ["error"]` to `"no-console": ["error", { allow: ["warn", "error"] }]` (we at least log the error messages of the floating promises) - fixed lint/compile errors 7622: Resolve TupleStructPat in SourceAnalyzer::resolve_path r=Veykril a=Veykril Closes #7594 bors r+ Co-authored-by: Sahandevs <sahandevs@gmail.com> Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
ff5ef2830c
@ -222,8 +222,9 @@ impl SourceAnalyzer {
|
||||
db: &dyn HirDatabase,
|
||||
path: &ast::Path,
|
||||
) -> Option<PathResolution> {
|
||||
let parent = || path.syntax().parent();
|
||||
let mut prefer_value_ns = false;
|
||||
if let Some(path_expr) = path.syntax().parent().and_then(ast::PathExpr::cast) {
|
||||
if let Some(path_expr) = parent().and_then(ast::PathExpr::cast) {
|
||||
let expr_id = self.expr_id(db, &path_expr.into())?;
|
||||
let infer = self.infer.as_ref()?;
|
||||
if let Some(assoc) = infer.assoc_resolutions_for_expr(expr_id) {
|
||||
@ -237,7 +238,7 @@ impl SourceAnalyzer {
|
||||
prefer_value_ns = true;
|
||||
}
|
||||
|
||||
if let Some(path_pat) = path.syntax().parent().and_then(ast::PathPat::cast) {
|
||||
if let Some(path_pat) = parent().and_then(ast::PathPat::cast) {
|
||||
let pat_id = self.pat_id(&path_pat.into())?;
|
||||
if let Some(assoc) = self.infer.as_ref()?.assoc_resolutions_for_pat(pat_id) {
|
||||
return Some(PathResolution::AssocItem(assoc.into()));
|
||||
@ -249,7 +250,7 @@ impl SourceAnalyzer {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(rec_lit) = path.syntax().parent().and_then(ast::RecordExpr::cast) {
|
||||
if let Some(rec_lit) = parent().and_then(ast::RecordExpr::cast) {
|
||||
let expr_id = self.expr_id(db, &rec_lit.into())?;
|
||||
if let Some(VariantId::EnumVariantId(variant)) =
|
||||
self.infer.as_ref()?.variant_resolution_for_expr(expr_id)
|
||||
@ -258,8 +259,12 @@ impl SourceAnalyzer {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(rec_pat) = path.syntax().parent().and_then(ast::RecordPat::cast) {
|
||||
let pat_id = self.pat_id(&rec_pat.into())?;
|
||||
if let Some(pat) = parent()
|
||||
.and_then(ast::RecordPat::cast)
|
||||
.map(ast::Pat::from)
|
||||
.or_else(|| parent().and_then(ast::TupleStructPat::cast).map(ast::Pat::from))
|
||||
{
|
||||
let pat_id = self.pat_id(&pat)?;
|
||||
if let Some(VariantId::EnumVariantId(variant)) =
|
||||
self.infer.as_ref()?.variant_resolution_for_pat(pat_id)
|
||||
{
|
||||
@ -272,7 +277,7 @@ impl SourceAnalyzer {
|
||||
|
||||
// Case where path is a qualifier of another path, e.g. foo::bar::Baz where we
|
||||
// trying to resolve foo::bar.
|
||||
if let Some(outer_path) = path.syntax().parent().and_then(ast::Path::cast) {
|
||||
if let Some(outer_path) = parent().and_then(ast::Path::cast) {
|
||||
if let Some(qualifier) = outer_path.qualifier() {
|
||||
if path == &qualifier {
|
||||
return resolve_hir_path_qualifier(db, &self.resolver, &hir_path);
|
||||
|
@ -1114,4 +1114,27 @@ trait Foo {
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_self_variant_with_payload() {
|
||||
check(
|
||||
r#"
|
||||
enum Foo { Bar() }
|
||||
|
||||
impl Foo {
|
||||
fn foo(self) {
|
||||
match self {
|
||||
Self::Bar$0() => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
"#,
|
||||
expect![[r#"
|
||||
Bar Variant FileId(0) 11..16 11..14 Other
|
||||
|
||||
FileId(0) 89..92 Other
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ module.exports = {
|
||||
"rules": {
|
||||
"camelcase": ["error"],
|
||||
"eqeqeq": ["error", "always", { "null": "ignore" }],
|
||||
"no-console": ["error"],
|
||||
"no-console": ["error", { allow: ["warn", "error"] }],
|
||||
"prefer-const": "error",
|
||||
"@typescript-eslint/member-delimiter-style": [
|
||||
"error",
|
||||
@ -33,6 +33,7 @@ module.exports = {
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"@typescript-eslint/no-unnecessary-type-assertion": "error"
|
||||
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
||||
"@typescript-eslint/no-floating-promises": "error"
|
||||
}
|
||||
};
|
||||
|
@ -11,7 +11,7 @@ export interface Env {
|
||||
}
|
||||
|
||||
function renderCommand(cmd: ra.CommandLink) {
|
||||
return `[${cmd.title}](command:${cmd.command}?${encodeURIComponent(JSON.stringify(cmd.arguments))} '${cmd.tooltip!}')`;
|
||||
return `[${cmd.title}](command:${cmd.command}?${encodeURIComponent(JSON.stringify(cmd.arguments))} '${cmd.tooltip}')`;
|
||||
}
|
||||
|
||||
function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownString {
|
||||
@ -138,7 +138,7 @@ export function createClient(serverPath: string, cwd: string, extraEnv: Env): lc
|
||||
command: "rust-analyzer.applyActionGroup",
|
||||
title: "",
|
||||
arguments: [items.map((item) => {
|
||||
return { label: item.title, arguments: item.command!!.arguments!![0] };
|
||||
return { label: item.title, arguments: item.command!.arguments![0] };
|
||||
})],
|
||||
};
|
||||
|
||||
|
@ -125,7 +125,7 @@ export function joinLines(ctx: Ctx): Cmd {
|
||||
ranges: editor.selections.map((it) => client.code2ProtocolConverter.asRange(it)),
|
||||
textDocument: ctx.client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document),
|
||||
});
|
||||
editor.edit((builder) => {
|
||||
await editor.edit((builder) => {
|
||||
client.protocol2CodeConverter.asTextEdits(items).forEach((edit: any) => {
|
||||
builder.replace(edit.range, edit.newText);
|
||||
});
|
||||
@ -236,7 +236,7 @@ export function ssr(ctx: Ctx): Cmd {
|
||||
const request = await vscode.window.showInputBox(options);
|
||||
if (!request) return;
|
||||
|
||||
vscode.window.withProgress({
|
||||
await vscode.window.withProgress({
|
||||
location: vscode.ProgressLocation.Notification,
|
||||
title: "Structured search replace in progress...",
|
||||
cancellable: false,
|
||||
@ -457,10 +457,10 @@ export function reloadWorkspace(ctx: Ctx): Cmd {
|
||||
}
|
||||
|
||||
export function showReferences(ctx: Ctx): Cmd {
|
||||
return (uri: string, position: lc.Position, locations: lc.Location[]) => {
|
||||
return async (uri: string, position: lc.Position, locations: lc.Location[]) => {
|
||||
const client = ctx.client;
|
||||
if (client) {
|
||||
vscode.commands.executeCommand(
|
||||
await vscode.commands.executeCommand(
|
||||
'editor.action.showReferences',
|
||||
vscode.Uri.parse(uri),
|
||||
client.protocol2CodeConverter.asPosition(position),
|
||||
@ -474,7 +474,7 @@ export function applyActionGroup(_ctx: Ctx): Cmd {
|
||||
return async (actions: { label: string; arguments: lc.CodeAction }[]) => {
|
||||
const selectedAction = await vscode.window.showQuickPick(actions);
|
||||
if (!selectedAction) return;
|
||||
vscode.commands.executeCommand(
|
||||
await vscode.commands.executeCommand(
|
||||
'rust-analyzer.resolveCodeAction',
|
||||
selectedAction.arguments,
|
||||
);
|
||||
@ -510,7 +510,7 @@ export function openDocs(ctx: Ctx): Cmd {
|
||||
const doclink = await client.sendRequest(ra.openDocs, { position, textDocument });
|
||||
|
||||
if (doclink != null) {
|
||||
vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(doclink));
|
||||
await vscode.commands.executeCommand("vscode.open", vscode.Uri.parse(doclink));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -77,7 +77,7 @@ async function getDebugConfiguration(ctx: Ctx, runnable: ra.Runnable): Promise<v
|
||||
}
|
||||
|
||||
if (!debugEngine) {
|
||||
vscode.window.showErrorMessage(`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb)`
|
||||
await vscode.window.showErrorMessage(`Install [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb)`
|
||||
+ ` or [MS C++ tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) extension for debugging.`);
|
||||
return;
|
||||
}
|
||||
@ -86,12 +86,14 @@ async function getDebugConfiguration(ctx: Ctx, runnable: ra.Runnable): Promise<v
|
||||
if (ctx.config.debug.openDebugPane) {
|
||||
debugOutput.show(true);
|
||||
}
|
||||
|
||||
const isMultiFolderWorkspace = vscode.workspace.workspaceFolders!.length > 1;
|
||||
const firstWorkspace = vscode.workspace.workspaceFolders![0]; // folder exists or RA is not active.
|
||||
// folder exists or RA is not active.
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
||||
const workspaceFolders = vscode.workspace.workspaceFolders!;
|
||||
const isMultiFolderWorkspace = workspaceFolders.length > 1;
|
||||
const firstWorkspace = workspaceFolders[0];
|
||||
const workspace = !isMultiFolderWorkspace || !runnable.args.workspaceRoot ?
|
||||
firstWorkspace :
|
||||
vscode.workspace.workspaceFolders!.find(w => runnable.args.workspaceRoot?.includes(w.uri.fsPath)) || firstWorkspace;
|
||||
workspaceFolders.find(w => runnable.args.workspaceRoot?.includes(w.uri.fsPath)) || firstWorkspace;
|
||||
|
||||
const wsFolder = path.normalize(workspace.uri.fsPath);
|
||||
const workspaceQualifier = isMultiFolderWorkspace ? `:${workspace.name}` : '';
|
||||
|
@ -36,7 +36,7 @@ export function activateInlayHints(ctx: Ctx) {
|
||||
maybeUpdater.onConfigChange, maybeUpdater, ctx.subscriptions
|
||||
);
|
||||
|
||||
maybeUpdater.onConfigChange();
|
||||
maybeUpdater.onConfigChange().catch(console.error);
|
||||
}
|
||||
|
||||
const typeHints = createHintStyle("type");
|
||||
|
@ -76,7 +76,7 @@ async function tryActivate(context: vscode.ExtensionContext) {
|
||||
// This a horribly, horribly wrong way to deal with this problem.
|
||||
ctx = await Ctx.create(config, context, serverPath, workspaceFolder.uri.fsPath);
|
||||
|
||||
setContextValue(RUST_PROJECT_CONTEXT_NAME, true);
|
||||
await setContextValue(RUST_PROJECT_CONTEXT_NAME, true);
|
||||
|
||||
// Commands which invokes manually via command palette, shortcut, etc.
|
||||
|
||||
@ -142,7 +142,7 @@ async function tryActivate(context: vscode.ExtensionContext) {
|
||||
}
|
||||
|
||||
export async function deactivate() {
|
||||
setContextValue(RUST_PROJECT_CONTEXT_NAME, undefined);
|
||||
await setContextValue(RUST_PROJECT_CONTEXT_NAME, undefined);
|
||||
await ctx?.client.stop();
|
||||
ctx = undefined;
|
||||
}
|
||||
@ -183,10 +183,10 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
|
||||
|
||||
const release = await downloadWithRetryDialog(state, async () => {
|
||||
return await fetchRelease("nightly", state.githubToken);
|
||||
}).catch((e) => {
|
||||
}).catch(async (e) => {
|
||||
log.error(e);
|
||||
if (state.releaseId === undefined) { // Show error only for the initial download
|
||||
vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly ${e}`);
|
||||
await vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly ${e}`);
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
@ -298,7 +298,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
|
||||
};
|
||||
const platform = platforms[`${process.arch} ${process.platform}`];
|
||||
if (platform === undefined) {
|
||||
vscode.window.showErrorMessage(
|
||||
await vscode.window.showErrorMessage(
|
||||
"Unfortunately we don't ship binaries for your platform yet. " +
|
||||
"You need to manually clone rust-analyzer repository and " +
|
||||
"run `cargo xtask install --server` to build the language server from sources. " +
|
||||
@ -433,6 +433,7 @@ function warnAboutExtensionConflicts() {
|
||||
vscode.window.showWarningMessage(
|
||||
`You have both the ${fst[0]} (${fst[1]}) and ${sec[0]} (${sec[1]}) ` +
|
||||
"plugins enabled. These are known to conflict and cause various functions of " +
|
||||
"both plugins to not work correctly. You should disable one of them.", "Got it");
|
||||
"both plugins to not work correctly. You should disable one of them.", "Got it")
|
||||
.then(() => { }, console.error);
|
||||
};
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ export async function selectRunnable(ctx: Ctx, prevRunnable?: RunnableQuickPick,
|
||||
if (items.length === 0) {
|
||||
// it is the debug case, run always has at least 'cargo check ...'
|
||||
// see crates\rust-analyzer\src\main_loop\handlers.rs, handle_runnables
|
||||
vscode.window.showErrorMessage("There's no debug target!");
|
||||
await vscode.window.showErrorMessage("There's no debug target!");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -65,8 +65,8 @@ export async function selectRunnable(ctx: Ctx, prevRunnable?: RunnableQuickPick,
|
||||
disposables.push(
|
||||
quickPick.onDidHide(() => close()),
|
||||
quickPick.onDidAccept(() => close(quickPick.selectedItems[0])),
|
||||
quickPick.onDidTriggerButton((_button) => {
|
||||
(async () => await makeDebugConfig(ctx, quickPick.activeItems[0].runnable))();
|
||||
quickPick.onDidTriggerButton(async (_button) => {
|
||||
await makeDebugConfig(ctx, quickPick.activeItems[0].runnable);
|
||||
close();
|
||||
}),
|
||||
quickPick.onDidChangeActive((active) => {
|
||||
@ -145,6 +145,7 @@ export async function createTask(runnable: ra.Runnable, config: Config): Promise
|
||||
overrideCargo: runnable.args.overrideCargo,
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
||||
const target = vscode.workspace.workspaceFolders![0]; // safe, see main activate()
|
||||
const cargoTask = await tasks.buildCargoTask(target, definition, runnable.label, args, config.cargoRunner, true);
|
||||
cargoTask.presentationOptions.clear = true;
|
||||
|
@ -62,7 +62,9 @@ function parseSnippet(snip: string): [string, [number, number]] | undefined {
|
||||
const m = snip.match(/\$(0|\{0:([^}]*)\})/);
|
||||
if (!m) return undefined;
|
||||
const placeholder = m[2] ?? "";
|
||||
const range: [number, number] = [m.index!!, placeholder.length];
|
||||
if (m.index == null)
|
||||
return undefined;
|
||||
const range: [number, number] = [m.index, placeholder.length];
|
||||
const insert = snip.replace(m[0], placeholder);
|
||||
return [insert, range];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user