Skip to content

Commit

Permalink
fix(lsp): allow on disk files to change (denoland#9746)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Mar 10, 2021
1 parent db96be7 commit 88a7fa3
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 75 deletions.
28 changes: 0 additions & 28 deletions cli/lsp/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,6 @@ impl Sources {
self.0.lock().unwrap().contains_key(specifier)
}

/// Provides the length of the source content, calculated in a way that should
/// match the behavior of JavaScript, where strings are stored effectively as
/// `&[u16]` and when counting "chars" we need to represent the string as a
/// UTF-16 string in Rust.
pub fn get_length_utf16(&self, specifier: &ModuleSpecifier) -> Option<usize> {
self.0.lock().unwrap().get_length_utf16(specifier)
}

pub fn get_line_index(
&self,
specifier: &ModuleSpecifier,
Expand Down Expand Up @@ -248,13 +240,6 @@ impl Inner {
false
}

fn get_length_utf16(&mut self, specifier: &ModuleSpecifier) -> Option<usize> {
let specifier =
resolve_specifier(specifier, &mut self.redirects, &self.http_cache)?;
let metadata = self.get_metadata(&specifier)?;
Some(metadata.length_utf16)
}

fn get_line_index(
&mut self,
specifier: &ModuleSpecifier,
Expand Down Expand Up @@ -471,19 +456,6 @@ mod tests {
assert_eq!(actual, "console.log(\"Hello World\");\n");
}

#[test]
fn test_sources_get_length_utf16() {
let (sources, _) = setup();
let c = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
let tests = c.join("tests");
let specifier =
resolve_path(&tests.join("001_hello.js").to_string_lossy()).unwrap();
let actual = sources.get_length_utf16(&specifier);
assert!(actual.is_some());
let actual = actual.unwrap();
assert_eq!(actual, 28);
}

#[test]
fn test_resolve_dependency_types() {
let (sources, location) = setup();
Expand Down
Loading

0 comments on commit 88a7fa3

Please sign in to comment.