diff options
| author | Ian Chamberlain <ichamberlain@juniper.net> | 2023-01-03 10:16:16 -0500 |
|---|---|---|
| committer | Ian Chamberlain <ichamberlain@juniper.net> | 2023-01-09 11:46:29 -0500 |
| commit | 1b8141b54cb5f89bd3dee7bfbab41109d1b48cb6 (patch) | |
| tree | 8b4a5f2270fa6e807cf0cf76174b1800e8c07315 /editors/code/src/client.ts | |
| parent | f32e20edb99a15d42984ec89f6b3986248845929 (diff) | |
| download | rust-1b8141b54cb5f89bd3dee7bfbab41109d1b48cb6.tar.gz rust-1b8141b54cb5f89bd3dee7bfbab41109d1b48cb6.zip | |
Parse + decorate rendered ANSI cargo output
Use ANSI control characters to display text decorations matching the VScode terminal theme, and strip them out when providing text content for rustc diagnostics. This adds the small `anser` library to parse the control codes, and it also supports HTML output so it should be fairly easy to switch to a rendered HTML/webview implementation if desired.
Diffstat (limited to 'editors/code/src/client.ts')
| -rw-r--r-- | editors/code/src/client.ts | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index e6595340aae..74cf44f42f7 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts @@ -3,6 +3,7 @@ import * as vscode from "vscode"; import * as ra from "../src/lsp_ext"; import * as Is from "vscode-languageclient/lib/common/utils/is"; import { assert } from "./util"; +import * as diagnostics from "./diagnostics"; import { WorkspaceEdit } from "vscode"; import { Config, substituteVSCodeVariables } from "./config"; import { randomUUID } from "crypto"; @@ -120,12 +121,12 @@ export async function createClient( }, async handleDiagnostics( uri: vscode.Uri, - diagnostics: vscode.Diagnostic[], + diagnosticList: vscode.Diagnostic[], next: lc.HandleDiagnosticsSignature ) { const preview = config.previewRustcOutput; const errorCode = config.useRustcErrorCode; - diagnostics.forEach((diag, idx) => { + diagnosticList.forEach((diag, idx) => { // Abuse the fact that VSCode leaks the LSP diagnostics data field through the // Diagnostic class, if they ever break this we are out of luck and have to go // back to the worst diagnostics experience ever:) @@ -154,8 +155,8 @@ export async function createClient( } diag.code = { target: vscode.Uri.from({ - scheme: "rust-analyzer-diagnostics-view", - path: "/diagnostic message", + scheme: diagnostics.URI_SCHEME, + path: `/diagnostic message [${idx.toString()}]`, fragment: uri.toString(), query: idx.toString(), }), @@ -163,7 +164,7 @@ export async function createClient( }; } }); - return next(uri, diagnostics); + return next(uri, diagnosticList); }, async provideHover( document: vscode.TextDocument, |
