mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
Fixes #10747
This commit is contained in:
parent
62bf403157
commit
633c5aab1f
3 changed files with 69 additions and 8 deletions
|
@ -447,7 +447,15 @@ impl Inner {
|
|||
))
|
||||
}?;
|
||||
|
||||
let config_file = ConfigFile::read(config_url.path())?;
|
||||
let config_file = {
|
||||
let buffer = config_url
|
||||
.to_file_path()
|
||||
.map_err(|_| anyhow!("Bad uri: \"{}\"", config_url))?;
|
||||
let path = buffer
|
||||
.to_str()
|
||||
.ok_or_else(|| anyhow!("Bad uri: \"{}\"", config_url))?;
|
||||
ConfigFile::read(path)?
|
||||
};
|
||||
let (value, maybe_ignored_options) = config_file.as_compiler_options()?;
|
||||
tsconfig.merge(&value);
|
||||
self.maybe_config_uri = Some(config_url);
|
||||
|
|
|
@ -31,7 +31,10 @@ fn init(init_path: &str) -> LspClient {
|
|||
client
|
||||
}
|
||||
|
||||
fn did_open<V>(client: &mut LspClient, params: V)
|
||||
fn did_open<V>(
|
||||
client: &mut LspClient,
|
||||
params: V,
|
||||
) -> Vec<lsp::PublishDiagnosticsParams>
|
||||
where
|
||||
V: Serialize,
|
||||
{
|
||||
|
@ -45,12 +48,16 @@ where
|
|||
.write_response(id, json!({ "enable": true }))
|
||||
.unwrap();
|
||||
|
||||
let (method, _) = client.read_notification::<Value>().unwrap();
|
||||
assert_eq!(method, "textDocument/publishDiagnostics");
|
||||
let (method, _) = client.read_notification::<Value>().unwrap();
|
||||
assert_eq!(method, "textDocument/publishDiagnostics");
|
||||
let (method, _) = client.read_notification::<Value>().unwrap();
|
||||
assert_eq!(method, "textDocument/publishDiagnostics");
|
||||
let mut diagnostics = vec![];
|
||||
for _ in 0..3 {
|
||||
let (method, response) = client
|
||||
.read_notification::<lsp::PublishDiagnosticsParams>()
|
||||
.unwrap();
|
||||
assert_eq!(method, "textDocument/publishDiagnostics");
|
||||
diagnostics.push(response.unwrap());
|
||||
}
|
||||
|
||||
diagnostics
|
||||
}
|
||||
|
||||
fn shutdown(client: &mut LspClient) {
|
||||
|
@ -66,6 +73,47 @@ fn lsp_startup_shutdown() {
|
|||
shutdown(&mut client);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lsp_init_tsconfig() {
|
||||
let temp_dir = TempDir::new().expect("could not create temp dir");
|
||||
let mut params: lsp::InitializeParams =
|
||||
serde_json::from_value(load_fixture("initialize_params.json")).unwrap();
|
||||
let tsconfig =
|
||||
serde_json::to_vec_pretty(&load_fixture("lib.tsconfig.json")).unwrap();
|
||||
fs::write(temp_dir.path().join("lib.tsconfig.json"), tsconfig).unwrap();
|
||||
|
||||
params.root_uri = Some(Url::from_file_path(temp_dir.path()).unwrap());
|
||||
if let Some(Value::Object(mut map)) = params.initialization_options {
|
||||
map.insert("config".to_string(), json!("./lib.tsconfig.json"));
|
||||
params.initialization_options = Some(Value::Object(map));
|
||||
}
|
||||
|
||||
let deno_exe = deno_exe_path();
|
||||
let mut client = LspClient::new(&deno_exe).unwrap();
|
||||
client
|
||||
.write_request::<_, _, Value>("initialize", params)
|
||||
.unwrap();
|
||||
|
||||
client.write_notification("initialized", json!({})).unwrap();
|
||||
|
||||
let diagnostics = did_open(
|
||||
&mut client,
|
||||
json!({
|
||||
"textDocument": {
|
||||
"uri": "file:///a/file.ts",
|
||||
"languageId": "typescript",
|
||||
"version": 1,
|
||||
"text": "location.pathname;\n"
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
let diagnostics = diagnostics.into_iter().flat_map(|x| x.diagnostics);
|
||||
assert_eq!(diagnostics.count(), 0);
|
||||
|
||||
shutdown(&mut client);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lsp_hover() {
|
||||
let mut client = init("initialize_params.json");
|
||||
|
|
5
cli/tests/lsp/lib.tsconfig.json
Normal file
5
cli/tests/lsp/lib.tsconfig.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["deno.ns", "deno.unstable", "dom"]
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue