Skip to content

Commit

Permalink
feat: run/cancel/clear flycheck
Browse files Browse the repository at this point in the history
  • Loading branch information
fannheyward committed Dec 19, 2022
1 parent 0975292 commit e259fca
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ You can use these commands by `:CocCommand XYZ`.
| rust-analyzer.viewCrateGraph | View Crate Graph |
| rust-analyzer.viewFullCrateGraph | View Crate Graph (Full) |
| rust-analyzer.shuffleCrateGraph | Shuffle Crate Graph |
| rust-analyzer.runFlycheck | Run flycheck |
| rust-analyzer.cancelFlycheck | Cancel running flychecks |
| rust-analyzer.clearFlycheck | Clear flycheck diagnostics |

## Highlight Group

Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1177,11 +1177,21 @@
"title": "Move item down",
"category": "Rust Analyzer"
},
{
"command": "rust-analyzer.runFlycheck",
"title": "Run flycheck",
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.cancelFlycheck",
"title": "Cancel running flychecks",
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.clearFlycheck",
"title": "Clear flycheck diagnostics",
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.explainError",
"title": "Explain the currently hovered diagnostic",
Expand Down
17 changes: 16 additions & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,24 @@ export function applySnippetWorkspaceEditCommand(): Cmd {
};
}

export function runFlycheck(ctx: Ctx): Cmd {
return async () => {
const { document } = await workspace.getCurrentState();
if (!isRustDocument(document)) return;

ctx.client.sendNotification(ra.runFlycheck, { textDocument: { uri: document.uri } });
};
}

export function cancelFlycheck(ctx: Ctx): Cmd {
return async () => {
await ctx.client.sendRequest(ra.cancelFlycheck);
ctx.client.sendNotification(ra.cancelFlycheck);
};
}

export function clearFlycheck(ctx: Ctx): Cmd {
return async () => {
ctx.client.sendNotification(ra.clearFlycheck);
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export async function activate(context: ExtensionContext): Promise<void> {
ctx.registerCommand('matchingBrace', cmds.matchingBrace);
ctx.registerCommand('openCargoToml', cmds.openCargoToml);
ctx.registerCommand('serverVersion', cmds.serverVersion);
ctx.registerCommand('runFlycheck', cmds.runFlycheck);
ctx.registerCommand('cancelFlycheck', cmds.cancelFlycheck);
ctx.registerCommand('clearFlycheck', cmds.clearFlycheck);
ctx.registerCommand('analyzerStatus', cmds.analyzerStatus);
ctx.registerCommand('viewCrateGraph', cmds.viewCrateGraph);
ctx.registerCommand('shuffleCrateGraph', cmds.shuffleCrateGraph);
Expand Down
8 changes: 6 additions & 2 deletions src/lsp_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ export const expandMacro = new lc.RequestType<ExpandMacroParams, ExpandedMacro |

export const relatedTests = new lc.RequestType<lc.TextDocumentPositionParams, TestInfo[], void>('rust-analyzer/relatedTests');

export const cancelFlycheck = new lc.RequestType0<void, void>('rust-analyzer/cancelFlycheck');
export const cancelFlycheck = new lc.NotificationType0('rust-analyzer/cancelFlycheck');
export const clearFlycheck = new lc.NotificationType0('rust-analyzer/clearFlycheck');
export const runFlycheck = new lc.NotificationType<{
textDocument: lc.TextDocumentIdentifier | null;
}>('rust-analyzer/runFlycheck');

// Experimental extensions

Expand Down Expand Up @@ -145,5 +149,5 @@ export interface MoveItemParams {

export const enum Direction {
Up = 'Up',
Down = 'Down'
Down = 'Down',
}

0 comments on commit e259fca

Please sign in to comment.