api Support svlint v0.9.0 with TextRuleEvent

This commit is contained in:
damc 2023-08-09 14:32:10 +02:00
parent 6715a1257c
commit f17f8cb98c
3 changed files with 19 additions and 5 deletions

14
Cargo.lock generated
View file

@ -98,6 +98,15 @@ dependencies = [
"textwrap",
]
[[package]]
name = "clap_complete"
version = "3.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f7a2e0a962c45ce25afce14220bc24f9dade0a1787f185cecf96bfba7847cd8"
dependencies = [
"clap",
]
[[package]]
name = "clap_derive"
version = "3.2.2"
@ -847,12 +856,13 @@ dependencies = [
[[package]]
name = "svlint"
version = "0.8.0"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfe8d1bf9b9c766fdb5f2a2efd87711879baacc49c65a9ab0439f3c4228dff80"
checksum = "d02dd9ca85b9f45ccb2964fe4ec59b29cab633d03d5a26c6a5e977020f94ce49"
dependencies = [
"anyhow",
"clap",
"clap_complete",
"colored",
"enquote",
"libloading",

View file

@ -30,7 +30,7 @@ log = "0.4"
serde = {version = "1", features = ["derive"]}
serde_json = "1"
simplelog = "0.12"
svlint = "0.8.0"
svlint = "0.9.0"
sv-parser = "0.13.1"
tokio = {version = "1.6", features = ["io-std", "macros", "rt", "test-util"]}
toml = "0.7"

View file

@ -7,7 +7,7 @@ use std::path::{Path, PathBuf};
use std::sync::{Arc, RwLock};
use sv_parser::{parse_sv_str, Define, DefineText};
use svlint::config::Config as LintConfig;
use svlint::linter::{Linter, LintFailed};
use svlint::linter::{Linter, LintFailed, TextRuleEvent};
use tower_lsp::jsonrpc::Result;
use tower_lsp::lsp_types::*;
use tower_lsp::{async_trait, Client, LanguageServer};
@ -97,13 +97,17 @@ impl Backend {
PathBuf::from("")
};
// Signal beginning of file to all TextRules, which *may* be used
// by textrules to reset their internal state.
let _ = linter.textrules_check(TextRuleEvent::StartOfFile, &src_path, &0);
// Iterate over lines in the file, applying each textrule to each line
// in turn.
let mut beg: usize = 0;
for line in s.split_inclusive('\n') {
let line_stripped = line.trim_end_matches(&['\n', '\r']);
for failed in linter.textrules_check(&line_stripped, &src_path, &beg) {
for failed in linter.textrules_check(TextRuleEvent::Line(&line_stripped), &src_path, &beg) {
Self::push_failed(failed, &src_path, &s, &mut ret);
}
beg += line.len();