mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
fix(lsp): cache unsupported import completion origins (#12661)
Fixes #12621
This commit is contained in:
parent
b6b25671b2
commit
91f8bdda2c
3 changed files with 58 additions and 11 deletions
|
@ -232,7 +232,7 @@ pub struct FileFetcher {
|
||||||
allow_remote: bool,
|
allow_remote: bool,
|
||||||
cache: FileCache,
|
cache: FileCache,
|
||||||
cache_setting: CacheSetting,
|
cache_setting: CacheSetting,
|
||||||
http_cache: HttpCache,
|
pub(crate) http_cache: HttpCache,
|
||||||
http_client: reqwest::Client,
|
http_client: reqwest::Client,
|
||||||
blob_store: BlobStore,
|
blob_store: BlobStore,
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,11 @@ async fn check_auto_config_registry(
|
||||||
.check_origin(&origin)
|
.check_origin(&origin)
|
||||||
.await
|
.await
|
||||||
.is_ok();
|
.is_ok();
|
||||||
|
// we are only sending registry state when enabled now, but changing
|
||||||
|
// the custom notification would make older versions of the plugin
|
||||||
|
// incompatible.
|
||||||
|
// TODO(@kitsonk) clean up protocol when doing v2 of suggestions
|
||||||
|
if suggestions {
|
||||||
client
|
client
|
||||||
.send_custom_notification::<lsp_custom::RegistryStateNotification>(
|
.send_custom_notification::<lsp_custom::RegistryStateNotification>(
|
||||||
lsp_custom::RegistryStateNotificationParams {
|
lsp_custom::RegistryStateNotificationParams {
|
||||||
|
@ -83,6 +88,7 @@ async fn check_auto_config_registry(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Ranges from the graph for specifiers include the leading and trailing quote,
|
/// Ranges from the graph for specifiers include the leading and trailing quote,
|
||||||
/// which we want to ignore when replacing text.
|
/// which we want to ignore when replacing text.
|
||||||
|
|
|
@ -382,10 +382,20 @@ impl ModuleRegistry {
|
||||||
&self,
|
&self,
|
||||||
specifier: &ModuleSpecifier,
|
specifier: &ModuleSpecifier,
|
||||||
) -> Result<Vec<RegistryConfiguration>, AnyError> {
|
) -> Result<Vec<RegistryConfiguration>, AnyError> {
|
||||||
let file = self
|
let fetch_result = self
|
||||||
.file_fetcher
|
.file_fetcher
|
||||||
.fetch(specifier, &mut Permissions::allow_all())
|
.fetch(specifier, &mut Permissions::allow_all())
|
||||||
.await?;
|
.await;
|
||||||
|
// if there is an error fetching, we will cache an empty file, so that
|
||||||
|
// subsequent requests they are just an empty doc which will error without
|
||||||
|
// needing to connect to the remote URL
|
||||||
|
if fetch_result.is_err() {
|
||||||
|
self
|
||||||
|
.file_fetcher
|
||||||
|
.http_cache
|
||||||
|
.set(specifier, HashMap::default(), &[])?;
|
||||||
|
}
|
||||||
|
let file = fetch_result?;
|
||||||
let config: RegistryConfigurationJson = serde_json::from_str(&file.source)?;
|
let config: RegistryConfigurationJson = serde_json::from_str(&file.source)?;
|
||||||
validate_config(&config)?;
|
validate_config(&config)?;
|
||||||
Ok(config.registries)
|
Ok(config.registries)
|
||||||
|
@ -1203,4 +1213,35 @@ mod tests {
|
||||||
assert!(actual.contains(&"module".to_owned()));
|
assert!(actual.contains(&"module".to_owned()));
|
||||||
assert!(actual.contains(&"version".to_owned()));
|
assert!(actual.contains(&"version".to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_check_origin_supported() {
|
||||||
|
let _g = test_util::http_server();
|
||||||
|
let temp_dir = TempDir::new().expect("could not create tmp");
|
||||||
|
let location = temp_dir.path().join("registries");
|
||||||
|
let module_registry = ModuleRegistry::new(&location);
|
||||||
|
let result = module_registry.check_origin("http://localhost:4545").await;
|
||||||
|
assert!(result.is_ok());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_check_origin_not_supported() {
|
||||||
|
let _g = test_util::http_server();
|
||||||
|
let temp_dir = TempDir::new().expect("could not create tmp");
|
||||||
|
let location = temp_dir.path().join("registries");
|
||||||
|
let module_registry = ModuleRegistry::new(&location);
|
||||||
|
let result = module_registry.check_origin("https://deno.com").await;
|
||||||
|
assert!(result.is_err());
|
||||||
|
let err = result.unwrap_err().to_string();
|
||||||
|
assert!(err
|
||||||
|
.contains("https://deno.com/.well-known/deno-import-intellisense.json"));
|
||||||
|
|
||||||
|
// because we are caching an empty file when we hit an error with import
|
||||||
|
// detection when fetching the config file, we should have an error now that
|
||||||
|
// indicates trying to parse an empty file.
|
||||||
|
let result = module_registry.check_origin("https://deno.com").await;
|
||||||
|
assert!(result.is_err());
|
||||||
|
let err = result.unwrap_err().to_string();
|
||||||
|
assert!(err.contains("EOF while parsing a value at line 1 column 0"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue