Skip to content

Commit 38e6eb6

Browse files
committed
Add vhdl_ls no-lint argument
1 parent 5e10f34 commit 38e6eb6

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

vhdl_ls/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ mod rpc_channel;
1212
mod stdio_server;
1313
mod vhdl_server;
1414
pub use crate::stdio_server::start;
15+
pub use crate::vhdl_server::VHDLServerSettings;

vhdl_ls/src/main.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@
55
// Copyright (c) 2018, Olof Kraigher olof.kraigher@gmail.com
66

77
use clap::Parser;
8+
use vhdl_ls::VHDLServerSettings;
89

910
#[derive(Parser)]
1011
#[command(author, version, about, long_about = None)]
11-
struct Args {}
12+
struct Args {
13+
/// Disable diagnostic messages, only use navigation and hover features
14+
#[arg(long, default_value_t = false)]
15+
no_lint: bool,
16+
}
1217

1318
fn main() {
14-
Args::parse();
19+
let args = Args::parse();
1520

1621
env_logger::init();
1722
log::info!("Starting language server");
18-
vhdl_ls::start();
23+
vhdl_ls::start(VHDLServerSettings {
24+
no_lint: args.no_lint,
25+
});
1926
}

vhdl_ls/src/stdio_server.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ use std::{cell::RefCell, rc::Rc};
1414

1515
use crate::rpc_channel::RpcChannel;
1616
use crate::vhdl_server::VHDLServer;
17+
use crate::vhdl_server::VHDLServerSettings;
1718

1819
/// Set up the IO channel for `stdio` and start the VHDL language server.
19-
pub fn start() {
20+
pub fn start(settings: VHDLServerSettings) {
2021
let (connection, io_threads) = Connection::stdio();
2122
let connection_rpc = ConnectionRpcChannel::new(connection);
22-
let mut server = VHDLServer::new(connection_rpc.clone());
23+
let mut server = VHDLServer::new_settings(connection_rpc.clone(), settings);
2324

2425
connection_rpc.handle_initialization(&mut server);
2526
connection_rpc.main_event_loop(server);

vhdl_ls/src/vhdl_server.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,36 @@ use std::io;
1414
use std::path::{Path, PathBuf};
1515
use vhdl_lang::{Config, Diagnostic, Message, Project, Severity, Source, SrcPos};
1616

17+
#[derive(Default, Clone)]
18+
pub struct VHDLServerSettings {
19+
pub no_lint: bool,
20+
}
21+
1722
pub struct VHDLServer<T: RpcChannel + Clone> {
1823
rpc_channel: T,
24+
settings: VHDLServerSettings,
1925
// To have well defined unit tests that are not affected by environment
2026
use_external_config: bool,
2127
server: Option<InitializedVHDLServer<T>>,
2228
config_file: Option<PathBuf>,
2329
}
2430

2531
impl<T: RpcChannel + Clone> VHDLServer<T> {
26-
pub fn new(rpc_channel: T) -> VHDLServer<T> {
27-
Self::new_external_config(rpc_channel, true)
32+
pub fn new_settings(rpc_channel: T, settings: VHDLServerSettings) -> VHDLServer<T> {
33+
VHDLServer {
34+
rpc_channel,
35+
settings,
36+
use_external_config: true,
37+
server: None,
38+
config_file: None,
39+
}
2840
}
2941

42+
#[cfg(test)]
3043
fn new_external_config(rpc_channel: T, use_external_config: bool) -> VHDLServer<T> {
3144
VHDLServer {
3245
rpc_channel,
46+
settings: Default::default(),
3347
use_external_config,
3448
server: None,
3549
config_file: None,
@@ -86,7 +100,12 @@ impl<T: RpcChannel + Clone> VHDLServer<T> {
86100
pub fn initialize_request(&mut self, params: InitializeParams) -> InitializeResult {
87101
self.config_file = self.root_uri_config_file(&params);
88102
let config = self.load_config();
89-
let (server, result) = InitializedVHDLServer::new(self.rpc_channel.clone(), config, params);
103+
let (server, result) = InitializedVHDLServer::new(
104+
self.rpc_channel.clone(),
105+
self.settings.clone(),
106+
config,
107+
params,
108+
);
90109
self.server = Some(server);
91110
result
92111
}
@@ -212,6 +231,7 @@ impl<T: RpcChannel + Clone> VHDLServer<T> {
212231

213232
struct InitializedVHDLServer<T: RpcChannel> {
214233
rpc_channel: T,
234+
settings: VHDLServerSettings,
215235
init_params: InitializeParams,
216236
project: Project,
217237
files_with_notifications: FnvHashMap<Url, ()>,
@@ -235,13 +255,15 @@ impl<T: RpcChannel> RpcChannel for InitializedVHDLServer<T> {
235255
impl<T: RpcChannel + Clone> InitializedVHDLServer<T> {
236256
pub fn new(
237257
rpc_channel: T,
258+
settings: VHDLServerSettings,
238259
config: Config,
239260
init_params: InitializeParams,
240261
) -> (InitializedVHDLServer<T>, InitializeResult) {
241262
let project = Project::from_config(&config, &mut MessageChannel::new(&rpc_channel));
242263

243264
let server = InitializedVHDLServer {
244265
rpc_channel,
266+
settings,
245267
init_params,
246268
project,
247269
files_with_notifications: FnvHashMap::default(),
@@ -303,6 +325,10 @@ impl<T: RpcChannel + Clone> InitializedVHDLServer<T> {
303325
}
304326

305327
fn publish_diagnostics(&mut self) {
328+
if self.settings.no_lint {
329+
return;
330+
}
331+
306332
let supports_related_information = self.client_supports_related_information();
307333
let diagnostics = self.project.analyse();
308334
let diagnostics = {

0 commit comments

Comments
 (0)