完成返回诊断器的接口
This commit is contained in:
parent
fa7b42f09b
commit
574c50325e
@ -30,17 +30,17 @@ pub use modelsim::*;
|
|||||||
/// - uri: 当前正在诊断的文件的 uri
|
/// - uri: 当前正在诊断的文件的 uri
|
||||||
/// - rope: 当前正在诊断的文件在后端增量更新的文本内容
|
/// - rope: 当前正在诊断的文件在后端增量更新的文本内容
|
||||||
/// - files: 所有 hdl 文件,方便后续进行联合诊断使用
|
/// - files: 所有 hdl 文件,方便后续进行联合诊断使用
|
||||||
/// - configuration: 前端关于 lsp 相关的配置
|
|
||||||
/// - server: 服务实例
|
/// - server: 服务实例
|
||||||
pub fn provide_diagnostics(
|
pub fn provide_diagnostics(
|
||||||
uri: Url,
|
uri: Url,
|
||||||
rope: &Rope,
|
rope: &Rope,
|
||||||
configuration: &LspConfiguration,
|
|
||||||
server: &LspServer
|
server: &LspServer
|
||||||
) -> PublishDiagnosticsParams {
|
) -> PublishDiagnosticsParams {
|
||||||
let mut diagnostics = Vec::<Diagnostic>::new();
|
let mut diagnostics = Vec::<Diagnostic>::new();
|
||||||
let language_id = get_language_id_by_uri(&uri);
|
let language_id = get_language_id_by_uri(&uri);
|
||||||
|
|
||||||
|
let configuration = server.configuration.read().unwrap();
|
||||||
|
|
||||||
// 选择对应语言的 lsp
|
// 选择对应语言的 lsp
|
||||||
let linter_configuration = match language_id.as_str() {
|
let linter_configuration = match language_id.as_str() {
|
||||||
"vhdl" => Some(&configuration.vhdl_linter_configuration),
|
"vhdl" => Some(&configuration.vhdl_linter_configuration),
|
||||||
|
@ -7,7 +7,8 @@ use request::{
|
|||||||
fast::SyncFastApi,
|
fast::SyncFastApi,
|
||||||
config::UpdateConfigurationApi,
|
config::UpdateConfigurationApi,
|
||||||
primitives::DoPrimitivesJudgeApi,
|
primitives::DoPrimitivesJudgeApi,
|
||||||
linter::LinterStatusApi
|
linter::LinterStatusApi,
|
||||||
|
linter::DoLintApi
|
||||||
};
|
};
|
||||||
|
|
||||||
use log::info;
|
use log::info;
|
||||||
@ -59,6 +60,7 @@ async fn main() {
|
|||||||
.custom_method("api/update-configuration", UpdateConfigurationApi)
|
.custom_method("api/update-configuration", UpdateConfigurationApi)
|
||||||
.custom_method("api/sync-fast", SyncFastApi)
|
.custom_method("api/sync-fast", SyncFastApi)
|
||||||
.custom_method("api/linter-status", LinterStatusApi)
|
.custom_method("api/linter-status", LinterStatusApi)
|
||||||
|
.custom_method("api/do-lint", DoLintApi)
|
||||||
.finish();
|
.finish();
|
||||||
|
|
||||||
Server::new(stdin, stdout, socket)
|
Server::new(stdin, stdout, socket)
|
||||||
|
@ -4,9 +4,11 @@ use std::future;
|
|||||||
use log::info;
|
use log::info;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tower_lsp::jsonrpc::Result;
|
use tower_lsp::jsonrpc::Result;
|
||||||
|
use tower_lsp::lsp_types::{Diagnostic, Url};
|
||||||
|
|
||||||
use crate::diagnostics::{AbstractLinterConfiguration, LinterStatus};
|
use crate::diagnostics::{provide_diagnostics, AbstractLinterConfiguration, LinterStatus};
|
||||||
use crate::server::Backend;
|
use crate::server::Backend;
|
||||||
|
use crate::utils::from_uri_to_escape_path_string;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct LinterStatusApi;
|
pub struct LinterStatusApi;
|
||||||
@ -91,4 +93,42 @@ fn get_linter_status(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct DoLintApi;
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct DoLintParams {
|
||||||
|
path: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl <'a>tower_lsp::jsonrpc::Method<&'a Arc<Backend>, (DoLintParams, ), Result<Vec<Diagnostic>>> for DoLintApi {
|
||||||
|
type Future = future::Ready<Result<Vec<Diagnostic>>>;
|
||||||
|
|
||||||
|
fn invoke(&self, _server: &'a Arc<Backend>, _params: (DoLintParams, )) -> Self::Future {
|
||||||
|
let path = _params.0.path;
|
||||||
|
let uri = Url::from_file_path(&path).unwrap();
|
||||||
|
let path_string = from_uri_to_escape_path_string(&uri).unwrap();
|
||||||
|
let server = &_server.server;
|
||||||
|
|
||||||
|
let result = if let Some(source) = server.srcs.get_source(&path_string) {
|
||||||
|
let source = source.read().unwrap();
|
||||||
|
let diags_param = provide_diagnostics(uri, &source.text, server);
|
||||||
|
Ok(diags_param.diagnostics)
|
||||||
|
} else {
|
||||||
|
Err(tower_lsp::jsonrpc::Error {
|
||||||
|
code: tower_lsp::jsonrpc::ErrorCode::InvalidRequest,
|
||||||
|
message: Cow::Owned(format!("文件尚未初始化 {}", path)),
|
||||||
|
data: None
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
future::ready(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -62,7 +62,6 @@ impl LspServer {
|
|||||||
let diagnostics = provide_diagnostics(
|
let diagnostics = provide_diagnostics(
|
||||||
uri,
|
uri,
|
||||||
&source.text,
|
&source.text,
|
||||||
&self.configuration.read().unwrap(),
|
|
||||||
&self
|
&self
|
||||||
);
|
);
|
||||||
diagnostics
|
diagnostics
|
||||||
@ -113,7 +112,6 @@ impl LspServer {
|
|||||||
provide_diagnostics(
|
provide_diagnostics(
|
||||||
uri,
|
uri,
|
||||||
&source.text,
|
&source.text,
|
||||||
&self.configuration.read().unwrap(),
|
|
||||||
&self
|
&self
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user