mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
support lsp
This commit is contained in:
parent
67756b55f2
commit
514c34903d
2 changed files with 23 additions and 10 deletions
|
@ -167,18 +167,18 @@ pub fn discover(flags: &crate::Flags) -> Result<Option<ConfigFile>, AnyError> {
|
||||||
} else {
|
} else {
|
||||||
let mut checked = HashSet::new();
|
let mut checked = HashSet::new();
|
||||||
for f in flags.config_path_args() {
|
for f in flags.config_path_args() {
|
||||||
if let Some(cf) = discover_inner(&f, &mut checked)? {
|
if let Some(cf) = discover_from(&f, &mut checked)? {
|
||||||
return Ok(Some(cf));
|
return Ok(Some(cf));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// From CWD walk up to root looking for deno.json or deno.jsonc
|
// From CWD walk up to root looking for deno.json or deno.jsonc
|
||||||
let cwd = std::env::current_dir()?;
|
let cwd = std::env::current_dir()?;
|
||||||
discover_inner(&cwd, &mut checked)
|
discover_from(&cwd, &mut checked)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn discover_inner(
|
pub fn discover_from(
|
||||||
start: &Path,
|
start: &Path,
|
||||||
checked: &mut HashSet<PathBuf>,
|
checked: &mut HashSet<PathBuf>,
|
||||||
) -> Result<Option<ConfigFile>, AnyError> {
|
) -> Result<Option<ConfigFile>, AnyError> {
|
||||||
|
@ -882,12 +882,12 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn discover_inner_success() {
|
fn discover_from_success() {
|
||||||
// testdata/fmt/deno.jsonc exists
|
// testdata/fmt/deno.jsonc exists
|
||||||
let testdata = test_util::testdata_path();
|
let testdata = test_util::testdata_path();
|
||||||
let c_md = testdata.join("fmt/with_config/subdir/c.md");
|
let c_md = testdata.join("fmt/with_config/subdir/c.md");
|
||||||
let mut checked = HashSet::new();
|
let mut checked = HashSet::new();
|
||||||
let config_file = discover_inner(&c_md, &mut checked).unwrap().unwrap();
|
let config_file = discover_from(&c_md, &mut checked).unwrap().unwrap();
|
||||||
assert!(checked.contains(c_md.parent().unwrap()));
|
assert!(checked.contains(c_md.parent().unwrap()));
|
||||||
assert!(!checked.contains(&testdata));
|
assert!(!checked.contains(&testdata));
|
||||||
let fmt_config = config_file.to_fmt_config().unwrap().unwrap();
|
let fmt_config = config_file.to_fmt_config().unwrap().unwrap();
|
||||||
|
@ -902,16 +902,16 @@ mod tests {
|
||||||
checked.insert(a.to_path_buf());
|
checked.insert(a.to_path_buf());
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we call discover_inner again starting at testdata, we ought to get None.
|
// If we call discover_from again starting at testdata, we ought to get None.
|
||||||
assert!(discover_inner(&testdata, &mut checked).unwrap().is_none());
|
assert!(discover_from(&testdata, &mut checked).unwrap().is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn discover_inner_malformed() {
|
fn discover_from_malformed() {
|
||||||
let testdata = test_util::testdata_path();
|
let testdata = test_util::testdata_path();
|
||||||
let d = testdata.join("malformed_config/");
|
let d = testdata.join("malformed_config/");
|
||||||
let mut checked = HashSet::new();
|
let mut checked = HashSet::new();
|
||||||
let err = discover_inner(&d, &mut checked).unwrap_err();
|
let err = discover_from(&d, &mut checked).unwrap_err();
|
||||||
assert!(err.to_string().contains("Unable to parse config file"));
|
assert!(err.to_string().contains("Unable to parse config file"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -290,6 +290,8 @@ impl Inner {
|
||||||
Ok(navigation_tree)
|
Ok(navigation_tree)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(ry): We can just return ConfigFile and use ConfigFile::specifier
|
||||||
|
// instead of returning URL in the tuple.
|
||||||
/// Returns a tuple with parsed `ConfigFile` and `Url` pointing to that file.
|
/// Returns a tuple with parsed `ConfigFile` and `Url` pointing to that file.
|
||||||
/// If there's no config file specified in settings returns `None`.
|
/// If there's no config file specified in settings returns `None`.
|
||||||
fn get_config_file_and_url(
|
fn get_config_file_and_url(
|
||||||
|
@ -320,7 +322,18 @@ impl Inner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(None)
|
// Auto-discover config
|
||||||
|
|
||||||
|
let root_uri = maybe_root_uri.unwrap();
|
||||||
|
let root_path = root_uri.to_file_path().unwrap();
|
||||||
|
let mut checked = std::collections::HashSet::new();
|
||||||
|
let maybe_config =
|
||||||
|
crate::config_file::discover_from(&root_path, &mut checked)?;
|
||||||
|
Ok(maybe_config.map(|c| {
|
||||||
|
let s = c.specifier.clone();
|
||||||
|
lsp_log!(" Auto-resolved configuration file: \"{}\"", s);
|
||||||
|
(c, s)
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_diagnosable(&self, specifier: &ModuleSpecifier) -> bool {
|
fn is_diagnosable(&self, specifier: &ModuleSpecifier) -> bool {
|
||||||
|
|
Loading…
Reference in a new issue