Skip to content

Commit 96a10b1

Browse files
committed
Remove colors from Bend diagnostic output
Related to issue #1
1 parent 05990d2 commit 96a10b1

File tree

6 files changed

+24
-5
lines changed

6 files changed

+24
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ dashmap = "6.0"
1919
lazy_static = "1.5"
2020
itertools = "0.13"
2121
ropey = "1.6"
22+
regex = "1.7"
2223

2324
[build-dependencies]
2425
cc = "1.1"
25-
26-
[patch.crates-io]
27-
hvm = { git = "https://github.com/HigherOrderCO/hvm.git", branch = "parser-update" }

src/core/diagnostics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use bend::{check_book, imports::DefaultLoader, CompileOpts};
55
use tower_lsp::lsp_types::{self as lsp, Position};
66

77
use super::document::Document;
8+
use crate::utils::color_wrapper::treat_colors;
89

910
/// Checks a Bend file and return its diagnostics.
1011
pub fn check(doc: &Document) -> Diagnostics {
@@ -36,7 +37,7 @@ pub fn lsp_diagnostics(diagnostics: &Diagnostics) -> Vec<lsp::Diagnostic> {
3637

3738
fn treat_diagnostic(origin: &DiagnosticOrigin, diag: &Diagnostic) -> Option<lsp::Diagnostic> {
3839
Some(lsp::Diagnostic {
39-
message: format!("{}", diag.display_with_origin(origin)),
40+
message: treat_colors(&diag.display_with_origin(origin).to_string()),
4041
severity: match diag.severity {
4142
Severity::Allow => Some(lsp::DiagnosticSeverity::HINT),
4243
Severity::Warning => Some(lsp::DiagnosticSeverity::WARNING),

src/server/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::fs;
22

3-
// use bend::diagnostics::Diagnostic;
43
use dashmap::DashMap;
54
use tower_lsp::jsonrpc::Result;
65
use tower_lsp::lsp_types::{self as lsp, SemanticTokensRangeResult};

src/utils/color_wrapper.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Parts of this code are based on https://github.com/Aloso/to-html/blob/main/LICENSE,
2+
// which is MIT-licensed.
3+
4+
use lazy_static::lazy_static;
5+
use regex::Regex;
6+
7+
lazy_static! {
8+
pub static ref ANSI_REGEX: Regex =
9+
Regex::new(r"\u{1b}(\[[0-9;?]*[A-HJKSTfhilmnsu]|\(B)").unwrap();
10+
}
11+
12+
/// This function receives a string with color and highlighting information
13+
/// in ANSI color code format and treats them to be reported by the language server.
14+
///
15+
/// As tracked in issue #1, diagnostic highlighting still does not implement color
16+
/// information in VSCode, so for now we just remove color codes.
17+
pub fn treat_colors(text: &str) -> String {
18+
ANSI_REGEX.replace_all(text, "").to_string()
19+
}

src/utils/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pub(crate) mod lsp_log;
2+
pub(crate) mod color_wrapper;

0 commit comments

Comments
 (0)