mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix(lsp): only resolve sources with supported schemas (#8696)
Fixes #8695
This commit is contained in:
parent
de65312b7f
commit
1a72c9ba23
2 changed files with 17 additions and 2 deletions
|
@ -26,7 +26,7 @@ use std::pin::Pin;
|
|||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
|
||||
const SUPPORTED_SCHEMES: [&str; 3] = ["http", "https", "file"];
|
||||
pub const SUPPORTED_SCHEMES: [&str; 3] = ["http", "https", "file"];
|
||||
|
||||
/// A structure representing a source file.
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
|
|
|
@ -5,6 +5,7 @@ use super::text;
|
|||
|
||||
use crate::file_fetcher::get_source_from_bytes;
|
||||
use crate::file_fetcher::map_content_type;
|
||||
use crate::file_fetcher::SUPPORTED_SCHEMES;
|
||||
use crate::http_cache;
|
||||
use crate::http_cache::HttpCache;
|
||||
use crate::import_map::ImportMap;
|
||||
|
@ -279,7 +280,12 @@ impl Sources {
|
|||
&mut self,
|
||||
specifier: &ModuleSpecifier,
|
||||
) -> Option<ModuleSpecifier> {
|
||||
if specifier.as_url().scheme() == "file" {
|
||||
let scheme = specifier.as_url().scheme();
|
||||
if !SUPPORTED_SCHEMES.contains(&scheme) {
|
||||
return None;
|
||||
}
|
||||
|
||||
if scheme == "file" {
|
||||
if let Ok(path) = specifier.as_url().to_file_path() {
|
||||
if path.is_file() {
|
||||
return Some(specifier.clone());
|
||||
|
@ -377,4 +383,13 @@ mod tests {
|
|||
let actual = actual.unwrap();
|
||||
assert_eq!(actual, 28);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sources_resolve_specifier_non_supported_schema() {
|
||||
let (mut sources, _) = setup();
|
||||
let specifier = ModuleSpecifier::resolve_url("foo://a/b/c.ts")
|
||||
.expect("could not create specifier");
|
||||
let actual = sources.resolve_specifier(&specifier);
|
||||
assert!(actual.is_none());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue