2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2020-12-07 05:46:39 -05:00
|
|
|
|
2022-03-20 21:33:37 -04:00
|
|
|
use super::logging::lsp_log;
|
2023-07-10 17:45:09 -04:00
|
|
|
use crate::args::ConfigFile;
|
|
|
|
use crate::lsp::logging::lsp_warn;
|
|
|
|
use crate::util::fs::canonicalize_path_maybe_not_exists;
|
2022-11-28 17:28:54 -05:00
|
|
|
use crate::util::path::specifier_to_file_path;
|
2021-05-20 05:56:48 -04:00
|
|
|
use deno_core::error::AnyError;
|
2023-07-10 17:45:09 -04:00
|
|
|
use deno_core::parking_lot::Mutex;
|
2020-12-07 05:46:39 -05:00
|
|
|
use deno_core::serde::Deserialize;
|
2021-07-20 21:50:43 -04:00
|
|
|
use deno_core::serde::Serialize;
|
2020-12-07 05:46:39 -05:00
|
|
|
use deno_core::serde_json;
|
|
|
|
use deno_core::serde_json::Value;
|
2021-05-09 21:16:04 -04:00
|
|
|
use deno_core::ModuleSpecifier;
|
2023-07-10 17:45:09 -04:00
|
|
|
use deno_lockfile::Lockfile;
|
2023-03-15 10:34:23 -04:00
|
|
|
use lsp::Url;
|
2021-05-20 05:56:48 -04:00
|
|
|
use std::collections::BTreeMap;
|
2021-04-08 21:27:27 -04:00
|
|
|
use std::collections::HashMap;
|
2023-07-10 17:45:09 -04:00
|
|
|
use std::path::PathBuf;
|
2021-05-20 05:56:48 -04:00
|
|
|
use std::sync::Arc;
|
2022-04-03 00:17:30 -04:00
|
|
|
use tower_lsp::lsp_types as lsp;
|
2021-12-15 13:23:43 -05:00
|
|
|
|
2021-05-09 21:16:04 -04:00
|
|
|
pub const SETTINGS_SECTION: &str = "deno";
|
|
|
|
|
2020-12-07 05:46:39 -05:00
|
|
|
#[derive(Debug, Clone, Default)]
|
|
|
|
pub struct ClientCapabilities {
|
2021-08-09 19:56:34 -04:00
|
|
|
pub code_action_disabled_support: bool,
|
|
|
|
pub line_folding_only: bool,
|
2022-10-14 08:04:38 -04:00
|
|
|
pub snippet_support: bool,
|
2020-12-07 05:46:39 -05:00
|
|
|
pub status_notification: bool,
|
2022-03-29 18:59:27 -04:00
|
|
|
/// The client provides the `experimental.testingApi` capability, which is
|
|
|
|
/// built around VSCode's testing API. It indicates that the server should
|
|
|
|
/// send notifications about tests discovered in modules.
|
|
|
|
pub testing_api: bool,
|
2021-01-04 16:52:20 -05:00
|
|
|
pub workspace_configuration: bool,
|
|
|
|
pub workspace_did_change_watched_files: bool,
|
2020-12-07 05:46:39 -05:00
|
|
|
}
|
|
|
|
|
2021-06-07 07:38:07 -04:00
|
|
|
fn is_true() -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2021-07-20 21:50:43 -04:00
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
2021-01-31 22:30:41 -05:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct CodeLensSettings {
|
2021-02-08 05:45:10 -05:00
|
|
|
/// Flag for providing implementation code lenses.
|
|
|
|
#[serde(default)]
|
|
|
|
pub implementations: bool,
|
|
|
|
/// Flag for providing reference code lenses.
|
2021-01-31 22:30:41 -05:00
|
|
|
#[serde(default)]
|
|
|
|
pub references: bool,
|
|
|
|
/// Flag for providing reference code lens on all functions. For this to have
|
|
|
|
/// an impact, the `references` flag needs to be `true`.
|
|
|
|
#[serde(default)]
|
|
|
|
pub references_all_functions: bool,
|
2021-06-07 07:38:07 -04:00
|
|
|
/// Flag for providing test code lens on `Deno.test` statements. There is
|
|
|
|
/// also the `test_args` setting, but this is not used by the server.
|
|
|
|
#[serde(default = "is_true")]
|
|
|
|
pub test: bool,
|
2021-01-31 22:30:41 -05:00
|
|
|
}
|
|
|
|
|
2021-03-15 18:01:41 -04:00
|
|
|
impl Default for CodeLensSettings {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
implementations: false,
|
|
|
|
references: false,
|
|
|
|
references_all_functions: false,
|
2021-06-07 07:38:07 -04:00
|
|
|
test: true,
|
2021-03-15 18:01:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-07 07:38:07 -04:00
|
|
|
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct CodeLensSpecifierSettings {
|
|
|
|
/// Flag for providing test code lens on `Deno.test` statements. There is
|
|
|
|
/// also the `test_args` setting, but this is not used by the server.
|
|
|
|
#[serde(default = "is_true")]
|
|
|
|
pub test: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for CodeLensSpecifierSettings {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self { test: true }
|
|
|
|
}
|
2021-06-01 07:53:08 -04:00
|
|
|
}
|
|
|
|
|
2021-07-20 21:50:43 -04:00
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
2021-03-15 18:01:41 -04:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct CompletionSettings {
|
|
|
|
#[serde(default)]
|
|
|
|
pub complete_function_calls: bool,
|
2021-06-01 07:53:08 -04:00
|
|
|
#[serde(default = "is_true")]
|
2021-03-15 18:01:41 -04:00
|
|
|
pub names: bool,
|
2021-06-01 07:53:08 -04:00
|
|
|
#[serde(default = "is_true")]
|
2021-03-15 18:01:41 -04:00
|
|
|
pub paths: bool,
|
2021-06-01 07:53:08 -04:00
|
|
|
#[serde(default = "is_true")]
|
2021-03-15 18:01:41 -04:00
|
|
|
pub auto_imports: bool,
|
2021-04-08 21:27:27 -04:00
|
|
|
#[serde(default)]
|
|
|
|
pub imports: ImportCompletionSettings,
|
2021-03-15 18:01:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for CompletionSettings {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
complete_function_calls: false,
|
|
|
|
names: true,
|
|
|
|
paths: true,
|
|
|
|
auto_imports: true,
|
2021-04-08 21:27:27 -04:00
|
|
|
imports: ImportCompletionSettings::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-15 22:39:43 -04:00
|
|
|
#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct InlayHintsSettings {
|
|
|
|
#[serde(default)]
|
|
|
|
pub parameter_names: InlayHintsParamNamesOptions,
|
|
|
|
#[serde(default)]
|
|
|
|
pub parameter_types: InlayHintsParamTypesOptions,
|
|
|
|
#[serde(default)]
|
|
|
|
pub variable_types: InlayHintsVarTypesOptions,
|
|
|
|
#[serde(default)]
|
|
|
|
pub property_declaration_types: InlayHintsPropDeclTypesOptions,
|
|
|
|
#[serde(default)]
|
|
|
|
pub function_like_return_types: InlayHintsFuncLikeReturnTypesOptions,
|
|
|
|
#[serde(default)]
|
|
|
|
pub enum_member_values: InlayHintsEnumMemberValuesOptions,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct InlayHintsParamNamesOptions {
|
|
|
|
#[serde(default)]
|
|
|
|
pub enabled: InlayHintsParamNamesEnabled,
|
|
|
|
#[serde(default = "is_true")]
|
|
|
|
pub suppress_when_argument_matches_name: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for InlayHintsParamNamesOptions {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
enabled: InlayHintsParamNamesEnabled::None,
|
|
|
|
suppress_when_argument_matches_name: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub enum InlayHintsParamNamesEnabled {
|
|
|
|
None,
|
|
|
|
Literals,
|
|
|
|
All,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for InlayHintsParamNamesEnabled {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct InlayHintsParamTypesOptions {
|
|
|
|
#[serde(default)]
|
|
|
|
pub enabled: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct InlayHintsVarTypesOptions {
|
|
|
|
#[serde(default)]
|
|
|
|
pub enabled: bool,
|
|
|
|
#[serde(default = "is_true")]
|
2022-10-28 14:48:14 -04:00
|
|
|
pub suppress_when_type_matches_name: bool,
|
2022-10-15 22:39:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for InlayHintsVarTypesOptions {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
enabled: false,
|
2022-10-28 14:48:14 -04:00
|
|
|
suppress_when_type_matches_name: true,
|
2022-10-15 22:39:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct InlayHintsPropDeclTypesOptions {
|
|
|
|
#[serde(default)]
|
|
|
|
pub enabled: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct InlayHintsFuncLikeReturnTypesOptions {
|
|
|
|
#[serde(default)]
|
|
|
|
pub enabled: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct InlayHintsEnumMemberValuesOptions {
|
|
|
|
#[serde(default)]
|
|
|
|
pub enabled: bool,
|
|
|
|
}
|
|
|
|
|
2021-07-20 21:50:43 -04:00
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
2021-04-08 21:27:27 -04:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct ImportCompletionSettings {
|
2021-06-01 07:53:08 -04:00
|
|
|
/// A flag that indicates if non-explicitly set origins should be checked for
|
|
|
|
/// supporting import suggestions.
|
|
|
|
#[serde(default = "is_true")]
|
|
|
|
pub auto_discover: bool,
|
|
|
|
/// A map of origins which have had explicitly set if import suggestions are
|
|
|
|
/// enabled.
|
2021-04-08 21:27:27 -04:00
|
|
|
#[serde(default)]
|
|
|
|
pub hosts: HashMap<String, bool>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for ImportCompletionSettings {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
2021-06-01 07:53:08 -04:00
|
|
|
auto_discover: true,
|
2021-04-08 21:27:27 -04:00
|
|
|
hosts: HashMap::default(),
|
2021-03-15 18:01:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-09 21:16:04 -04:00
|
|
|
/// Deno language server specific settings that can be applied uniquely to a
|
|
|
|
/// specifier.
|
2023-03-15 10:34:23 -04:00
|
|
|
#[derive(Debug, Default, Clone, Deserialize, PartialEq, Eq)]
|
2021-06-07 07:38:07 -04:00
|
|
|
#[serde(rename_all = "camelCase")]
|
2021-05-09 21:16:04 -04:00
|
|
|
pub struct SpecifierSettings {
|
|
|
|
/// A flag that indicates if Deno is enabled for this specifier or not.
|
|
|
|
pub enable: bool,
|
2022-03-20 21:33:37 -04:00
|
|
|
/// A list of paths, using the workspace folder as a base that should be Deno
|
|
|
|
/// enabled.
|
|
|
|
#[serde(default)]
|
|
|
|
pub enable_paths: Vec<String>,
|
2021-06-07 07:38:07 -04:00
|
|
|
/// Code lens specific settings for the resource.
|
|
|
|
#[serde(default)]
|
|
|
|
pub code_lens: CodeLensSpecifierSettings,
|
2021-05-09 21:16:04 -04:00
|
|
|
}
|
|
|
|
|
2022-03-29 18:59:27 -04:00
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct TestingSettings {
|
|
|
|
/// A vector of arguments which should be used when running the tests for
|
|
|
|
/// a workspace.
|
|
|
|
#[serde(default)]
|
|
|
|
pub args: Vec<String>,
|
|
|
|
/// Enable or disable the testing API if the client is capable of supporting
|
|
|
|
/// the testing API.
|
|
|
|
#[serde(default = "is_true")]
|
|
|
|
pub enable: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for TestingSettings {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
args: vec!["--allow-all".to_string(), "--no-check".to_string()],
|
|
|
|
enable: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-16 07:10:08 -04:00
|
|
|
fn default_to_true() -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2023-05-11 17:17:14 -04:00
|
|
|
fn default_document_preload_limit() -> usize {
|
|
|
|
1000
|
|
|
|
}
|
|
|
|
|
2023-01-03 10:59:48 -05:00
|
|
|
fn empty_string_none<'de, D: serde::Deserializer<'de>>(
|
|
|
|
d: D,
|
|
|
|
) -> Result<Option<String>, D::Error> {
|
|
|
|
let o: Option<String> = Option::deserialize(d)?;
|
|
|
|
Ok(o.filter(|s| !s.is_empty()))
|
|
|
|
}
|
|
|
|
|
2021-05-09 21:16:04 -04:00
|
|
|
/// Deno language server specific settings that are applied to a workspace.
|
2023-01-03 10:59:48 -05:00
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
2020-12-07 05:46:39 -05:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct WorkspaceSettings {
|
2021-05-09 21:16:04 -04:00
|
|
|
/// A flag that indicates if Deno is enabled for the workspace.
|
2021-06-01 07:53:08 -04:00
|
|
|
#[serde(default)]
|
2020-12-07 05:46:39 -05:00
|
|
|
pub enable: bool,
|
2021-05-09 21:16:04 -04:00
|
|
|
|
2022-03-20 21:33:37 -04:00
|
|
|
/// A list of paths, using the root_uri as a base that should be Deno enabled.
|
|
|
|
#[serde(default)]
|
|
|
|
pub enable_paths: Vec<String>,
|
|
|
|
|
2021-07-27 17:25:09 -04:00
|
|
|
/// An option that points to a path string of the path to utilise as the
|
|
|
|
/// cache/DENO_DIR for the language server.
|
2023-01-03 10:59:48 -05:00
|
|
|
#[serde(default, deserialize_with = "empty_string_none")]
|
2021-07-27 17:25:09 -04:00
|
|
|
pub cache: Option<String>,
|
|
|
|
|
2022-01-23 19:27:52 -05:00
|
|
|
/// Override the default stores used to validate certificates. This overrides
|
|
|
|
/// the environment variable `DENO_TLS_CA_STORE` if present.
|
|
|
|
pub certificate_stores: Option<Vec<String>>,
|
|
|
|
|
2021-05-10 12:16:39 -04:00
|
|
|
/// An option that points to a path string of the config file to apply to
|
2021-05-09 21:16:04 -04:00
|
|
|
/// code within the workspace.
|
2023-01-03 10:59:48 -05:00
|
|
|
#[serde(default, deserialize_with = "empty_string_none")]
|
2020-12-07 05:46:39 -05:00
|
|
|
pub config: Option<String>,
|
2021-05-09 21:16:04 -04:00
|
|
|
|
|
|
|
/// An option that points to a path string of the import map to apply to the
|
|
|
|
/// code within the workspace.
|
2023-01-03 10:59:48 -05:00
|
|
|
#[serde(default, deserialize_with = "empty_string_none")]
|
2020-12-07 05:46:39 -05:00
|
|
|
pub import_map: Option<String>,
|
2021-05-09 21:16:04 -04:00
|
|
|
|
|
|
|
/// Code lens specific settings for the workspace.
|
2021-03-15 18:01:41 -04:00
|
|
|
#[serde(default)]
|
|
|
|
pub code_lens: CodeLensSettings,
|
2021-05-09 21:16:04 -04:00
|
|
|
|
2022-10-15 22:39:43 -04:00
|
|
|
#[serde(default)]
|
|
|
|
pub inlay_hints: InlayHintsSettings,
|
|
|
|
|
2021-05-11 00:54:10 -04:00
|
|
|
/// A flag that indicates if internal debug logging should be made available.
|
|
|
|
#[serde(default)]
|
|
|
|
pub internal_debug: bool,
|
2021-01-04 16:52:20 -05:00
|
|
|
|
2021-05-09 21:16:04 -04:00
|
|
|
/// A flag that indicates if linting is enabled for the workspace.
|
2022-05-16 07:10:08 -04:00
|
|
|
#[serde(default = "default_to_true")]
|
2020-12-07 05:46:39 -05:00
|
|
|
pub lint: bool,
|
2021-05-09 21:16:04 -04:00
|
|
|
|
2023-05-11 17:17:14 -04:00
|
|
|
/// Limits the number of files that can be preloaded by the language server.
|
|
|
|
#[serde(default = "default_document_preload_limit")]
|
|
|
|
pub document_preload_limit: usize,
|
|
|
|
|
2021-05-09 21:16:04 -04:00
|
|
|
/// A flag that indicates if Dene should validate code against the unstable
|
|
|
|
/// APIs for the workspace.
|
2021-05-11 00:54:10 -04:00
|
|
|
#[serde(default)]
|
|
|
|
pub suggest: CompletionSettings,
|
|
|
|
|
2022-03-29 18:59:27 -04:00
|
|
|
/// Testing settings for the workspace.
|
|
|
|
#[serde(default)]
|
|
|
|
pub testing: TestingSettings,
|
|
|
|
|
2022-01-23 19:27:52 -05:00
|
|
|
/// An option which sets the cert file to use when attempting to fetch remote
|
|
|
|
/// resources. This overrides `DENO_CERT` if present.
|
2023-01-03 10:59:48 -05:00
|
|
|
#[serde(default, deserialize_with = "empty_string_none")]
|
2022-01-23 19:27:52 -05:00
|
|
|
pub tls_certificate: Option<String>,
|
|
|
|
|
|
|
|
/// An option, if set, will unsafely ignore certificate errors when fetching
|
|
|
|
/// remote resources.
|
|
|
|
#[serde(default)]
|
|
|
|
pub unsafely_ignore_certificate_errors: Option<Vec<String>>,
|
|
|
|
|
2021-01-04 16:52:20 -05:00
|
|
|
#[serde(default)]
|
2020-12-07 05:46:39 -05:00
|
|
|
pub unstable: bool,
|
|
|
|
}
|
|
|
|
|
2023-01-03 10:59:48 -05:00
|
|
|
impl Default for WorkspaceSettings {
|
|
|
|
fn default() -> Self {
|
|
|
|
WorkspaceSettings {
|
|
|
|
enable: false,
|
|
|
|
enable_paths: vec![],
|
|
|
|
cache: None,
|
|
|
|
certificate_stores: None,
|
|
|
|
config: None,
|
|
|
|
import_map: None,
|
|
|
|
code_lens: Default::default(),
|
|
|
|
inlay_hints: Default::default(),
|
|
|
|
internal_debug: false,
|
|
|
|
lint: true,
|
2023-05-11 17:17:14 -04:00
|
|
|
document_preload_limit: default_document_preload_limit(),
|
2023-01-03 10:59:48 -05:00
|
|
|
suggest: Default::default(),
|
|
|
|
testing: Default::default(),
|
|
|
|
tls_certificate: None,
|
|
|
|
unsafely_ignore_certificate_errors: None,
|
|
|
|
unstable: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-31 22:30:41 -05:00
|
|
|
impl WorkspaceSettings {
|
|
|
|
/// Determine if any code lenses are enabled at all. This allows short
|
|
|
|
/// circuiting when there are no code lenses enabled.
|
|
|
|
pub fn enabled_code_lens(&self) -> bool {
|
2021-03-15 18:01:41 -04:00
|
|
|
self.code_lens.implementations || self.code_lens.references
|
2021-01-31 22:30:41 -05:00
|
|
|
}
|
2022-10-15 22:39:43 -04:00
|
|
|
|
|
|
|
/// Determine if any inlay hints are enabled. This allows short circuiting
|
|
|
|
/// when there are no inlay hints enabled.
|
|
|
|
pub fn enabled_inlay_hints(&self) -> bool {
|
|
|
|
!matches!(
|
|
|
|
self.inlay_hints.parameter_names.enabled,
|
|
|
|
InlayHintsParamNamesEnabled::None
|
|
|
|
) || self.inlay_hints.parameter_types.enabled
|
|
|
|
|| self.inlay_hints.variable_types.enabled
|
|
|
|
|| self.inlay_hints.property_declaration_types.enabled
|
|
|
|
|| self.inlay_hints.function_like_return_types.enabled
|
|
|
|
|| self.inlay_hints.enum_member_values.enabled
|
|
|
|
}
|
2021-01-31 22:30:41 -05:00
|
|
|
}
|
|
|
|
|
2021-05-20 05:56:48 -04:00
|
|
|
#[derive(Debug, Clone, Default)]
|
|
|
|
pub struct ConfigSnapshot {
|
|
|
|
pub client_capabilities: ClientCapabilities,
|
2023-03-15 10:34:23 -04:00
|
|
|
pub enabled_paths: HashMap<Url, Vec<Url>>,
|
2023-07-10 21:03:19 -04:00
|
|
|
pub excluded_paths: Option<Vec<Url>>,
|
2021-05-20 05:56:48 -04:00
|
|
|
pub settings: Settings,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ConfigSnapshot {
|
2022-03-20 21:33:37 -04:00
|
|
|
/// Determine if the provided specifier is enabled or not.
|
2021-05-20 05:56:48 -04:00
|
|
|
pub fn specifier_enabled(&self, specifier: &ModuleSpecifier) -> bool {
|
2023-07-10 21:03:19 -04:00
|
|
|
specifier_enabled(
|
|
|
|
&self.enabled_paths,
|
|
|
|
self.excluded_paths.as_ref(),
|
|
|
|
&self.settings,
|
|
|
|
specifier,
|
|
|
|
)
|
2021-05-20 05:56:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-09 21:41:35 -05:00
|
|
|
#[derive(Debug, Default, Clone)]
|
2021-05-20 05:56:48 -04:00
|
|
|
pub struct Settings {
|
2023-03-15 10:34:23 -04:00
|
|
|
pub specifiers: BTreeMap<ModuleSpecifier, SpecifierSettings>,
|
2021-05-20 05:56:48 -04:00
|
|
|
pub workspace: WorkspaceSettings,
|
|
|
|
}
|
|
|
|
|
2023-07-10 17:45:09 -04:00
|
|
|
/// Contains the config file and dependent information.
|
|
|
|
#[derive(Debug)]
|
|
|
|
struct LspConfigFileInfo {
|
2023-07-10 21:03:19 -04:00
|
|
|
config_file: ConfigFile,
|
2023-07-10 17:45:09 -04:00
|
|
|
/// An optional deno.lock file, which is resolved relative to the config file.
|
2023-07-10 21:03:19 -04:00
|
|
|
maybe_lockfile: Option<Arc<Mutex<Lockfile>>>,
|
2023-07-10 17:45:09 -04:00
|
|
|
/// The canonicalized node_modules directory, which is found relative to the config file.
|
2023-07-10 21:03:19 -04:00
|
|
|
maybe_node_modules_dir: Option<PathBuf>,
|
|
|
|
excluded_paths: Vec<Url>,
|
2023-07-10 17:45:09 -04:00
|
|
|
}
|
|
|
|
|
2021-05-20 05:56:48 -04:00
|
|
|
#[derive(Debug)]
|
2020-12-07 05:46:39 -05:00
|
|
|
pub struct Config {
|
|
|
|
pub client_capabilities: ClientCapabilities,
|
2023-03-15 10:34:23 -04:00
|
|
|
enabled_paths: HashMap<Url, Vec<Url>>,
|
2022-03-20 21:33:37 -04:00
|
|
|
pub root_uri: Option<ModuleSpecifier>,
|
2022-01-25 10:30:38 -05:00
|
|
|
settings: Settings,
|
2022-03-20 21:33:37 -04:00
|
|
|
pub workspace_folders: Option<Vec<(ModuleSpecifier, lsp::WorkspaceFolder)>>,
|
2023-07-10 17:45:09 -04:00
|
|
|
/// An optional configuration file which has been specified in the client
|
|
|
|
/// options along with some data that is computed after the config file is set.
|
|
|
|
maybe_config_file_info: Option<LspConfigFileInfo>,
|
2020-12-07 05:46:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Config {
|
2022-01-25 10:30:38 -05:00
|
|
|
pub fn new() -> Self {
|
2021-05-20 05:56:48 -04:00
|
|
|
Self {
|
|
|
|
client_capabilities: ClientCapabilities::default(),
|
2022-03-20 21:33:37 -04:00
|
|
|
enabled_paths: Default::default(),
|
|
|
|
/// Root provided by the initialization parameters.
|
|
|
|
root_uri: None,
|
2022-01-25 10:30:38 -05:00
|
|
|
settings: Default::default(),
|
2021-06-21 17:18:32 -04:00
|
|
|
workspace_folders: None,
|
2023-07-10 17:45:09 -04:00
|
|
|
maybe_config_file_info: None,
|
2021-05-20 05:56:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-10 17:45:09 -04:00
|
|
|
pub fn maybe_node_modules_dir_path(&self) -> Option<&PathBuf> {
|
|
|
|
self
|
|
|
|
.maybe_config_file_info
|
|
|
|
.as_ref()
|
|
|
|
.and_then(|p| p.maybe_node_modules_dir.as_ref())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn maybe_config_file(&self) -> Option<&ConfigFile> {
|
|
|
|
self.maybe_config_file_info.as_ref().map(|c| &c.config_file)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn maybe_lockfile(&self) -> Option<&Arc<Mutex<Lockfile>>> {
|
|
|
|
self
|
|
|
|
.maybe_config_file_info
|
|
|
|
.as_ref()
|
|
|
|
.and_then(|c| c.maybe_lockfile.as_ref())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn clear_config_file(&mut self) {
|
|
|
|
self.maybe_config_file_info = None;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_config_file(&mut self, config_file: ConfigFile) {
|
|
|
|
self.maybe_config_file_info = Some(LspConfigFileInfo {
|
|
|
|
maybe_lockfile: resolve_lockfile_from_config(&config_file),
|
|
|
|
maybe_node_modules_dir: resolve_node_modules_dir(&config_file),
|
2023-07-10 21:03:19 -04:00
|
|
|
excluded_paths: config_file
|
|
|
|
.to_files_config()
|
|
|
|
.ok()
|
|
|
|
.flatten()
|
|
|
|
.map(|c| c.exclude)
|
|
|
|
.unwrap_or_default()
|
|
|
|
.into_iter()
|
|
|
|
.filter_map(|path| ModuleSpecifier::from_file_path(path).ok())
|
|
|
|
.collect(),
|
2023-07-10 17:45:09 -04:00
|
|
|
config_file,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-05-11 17:17:14 -04:00
|
|
|
pub fn workspace_settings(&self) -> &WorkspaceSettings {
|
|
|
|
&self.settings.workspace
|
2021-05-20 05:56:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Set the workspace settings directly, which occurs during initialization
|
|
|
|
/// and when the client does not support workspace configuration requests
|
2022-01-25 10:30:38 -05:00
|
|
|
pub fn set_workspace_settings(
|
|
|
|
&mut self,
|
|
|
|
value: Value,
|
|
|
|
) -> Result<(), AnyError> {
|
2021-05-20 05:56:48 -04:00
|
|
|
let workspace_settings = serde_json::from_value(value)?;
|
2022-01-25 10:30:38 -05:00
|
|
|
self.settings.workspace = workspace_settings;
|
2021-05-20 05:56:48 -04:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-01-19 17:10:14 -05:00
|
|
|
pub fn snapshot(&self) -> Arc<ConfigSnapshot> {
|
|
|
|
Arc::new(ConfigSnapshot {
|
2021-05-20 05:56:48 -04:00
|
|
|
client_capabilities: self.client_capabilities.clone(),
|
2022-03-20 21:33:37 -04:00
|
|
|
enabled_paths: self.enabled_paths.clone(),
|
2023-07-10 21:03:19 -04:00
|
|
|
excluded_paths: self
|
|
|
|
.maybe_config_file_info
|
|
|
|
.as_ref()
|
|
|
|
.map(|i| i.excluded_paths.clone()),
|
2022-01-25 10:30:38 -05:00
|
|
|
settings: self.settings.clone(),
|
2021-05-20 05:56:48 -04:00
|
|
|
})
|
2021-05-09 21:16:04 -04:00
|
|
|
}
|
|
|
|
|
2022-01-25 10:30:38 -05:00
|
|
|
pub fn has_specifier_settings(&self, specifier: &ModuleSpecifier) -> bool {
|
|
|
|
self.settings.specifiers.contains_key(specifier)
|
|
|
|
}
|
|
|
|
|
2021-05-09 21:16:04 -04:00
|
|
|
pub fn specifier_enabled(&self, specifier: &ModuleSpecifier) -> bool {
|
2023-07-10 21:03:19 -04:00
|
|
|
specifier_enabled(
|
|
|
|
&self.enabled_paths,
|
|
|
|
self
|
|
|
|
.maybe_config_file_info
|
|
|
|
.as_ref()
|
|
|
|
.map(|i| &i.excluded_paths),
|
|
|
|
&self.settings,
|
|
|
|
specifier,
|
|
|
|
)
|
2021-06-07 07:38:07 -04:00
|
|
|
}
|
|
|
|
|
2023-04-01 15:10:30 -04:00
|
|
|
/// Gets the directories or specifically enabled file paths based on the
|
|
|
|
/// workspace config.
|
|
|
|
///
|
|
|
|
/// WARNING: This may incorrectly have some directory urls as being
|
|
|
|
/// represented as file urls.
|
|
|
|
pub fn enabled_urls(&self) -> Vec<Url> {
|
2023-03-30 17:47:53 -04:00
|
|
|
let mut urls: Vec<Url> = Vec::new();
|
|
|
|
|
|
|
|
if !self.settings.workspace.enable && self.enabled_paths.is_empty() {
|
|
|
|
// do not return any urls when disabled
|
|
|
|
return urls;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (workspace, enabled_paths) in &self.enabled_paths {
|
|
|
|
if !enabled_paths.is_empty() {
|
|
|
|
urls.extend(enabled_paths.iter().cloned());
|
|
|
|
} else {
|
|
|
|
urls.push(workspace.clone());
|
|
|
|
}
|
|
|
|
}
|
2023-04-01 15:10:30 -04:00
|
|
|
|
2023-03-30 17:47:53 -04:00
|
|
|
if urls.is_empty() {
|
|
|
|
if let Some(root_dir) = &self.root_uri {
|
|
|
|
urls.push(root_dir.clone())
|
|
|
|
}
|
|
|
|
}
|
2023-04-01 15:10:30 -04:00
|
|
|
|
|
|
|
// sort for determinism
|
|
|
|
urls.sort();
|
2023-03-30 17:47:53 -04:00
|
|
|
urls
|
|
|
|
}
|
|
|
|
|
2021-06-07 07:38:07 -04:00
|
|
|
pub fn specifier_code_lens_test(&self, specifier: &ModuleSpecifier) -> bool {
|
2022-01-25 10:30:38 -05:00
|
|
|
let value = self
|
|
|
|
.settings
|
2021-06-07 07:38:07 -04:00
|
|
|
.specifiers
|
|
|
|
.get(specifier)
|
2023-03-15 10:34:23 -04:00
|
|
|
.map(|settings| settings.code_lens.test)
|
2022-01-25 10:30:38 -05:00
|
|
|
.unwrap_or_else(|| self.settings.workspace.code_lens.test);
|
2021-06-07 07:38:07 -04:00
|
|
|
value
|
2020-12-07 05:46:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn update_capabilities(
|
|
|
|
&mut self,
|
2021-01-29 14:34:33 -05:00
|
|
|
capabilities: &lsp::ClientCapabilities,
|
2020-12-07 05:46:39 -05:00
|
|
|
) {
|
|
|
|
if let Some(experimental) = &capabilities.experimental {
|
2021-06-15 13:22:28 -04:00
|
|
|
self.client_capabilities.status_notification = experimental
|
|
|
|
.get("statusNotification")
|
|
|
|
.and_then(|it| it.as_bool())
|
2022-03-29 18:59:27 -04:00
|
|
|
== Some(true);
|
|
|
|
self.client_capabilities.testing_api =
|
|
|
|
experimental.get("testingApi").and_then(|it| it.as_bool())
|
|
|
|
== Some(true);
|
2020-12-07 05:46:39 -05:00
|
|
|
}
|
2021-01-04 16:52:20 -05:00
|
|
|
|
|
|
|
if let Some(workspace) = &capabilities.workspace {
|
|
|
|
self.client_capabilities.workspace_configuration =
|
|
|
|
workspace.configuration.unwrap_or(false);
|
|
|
|
self.client_capabilities.workspace_did_change_watched_files = workspace
|
|
|
|
.did_change_watched_files
|
|
|
|
.and_then(|it| it.dynamic_registration)
|
|
|
|
.unwrap_or(false);
|
|
|
|
}
|
2021-04-02 02:21:07 -04:00
|
|
|
|
|
|
|
if let Some(text_document) = &capabilities.text_document {
|
|
|
|
self.client_capabilities.line_folding_only = text_document
|
|
|
|
.folding_range
|
|
|
|
.as_ref()
|
|
|
|
.and_then(|it| it.line_folding_only)
|
|
|
|
.unwrap_or(false);
|
2021-08-09 19:56:34 -04:00
|
|
|
self.client_capabilities.code_action_disabled_support = text_document
|
|
|
|
.code_action
|
|
|
|
.as_ref()
|
|
|
|
.and_then(|it| it.disabled_support)
|
|
|
|
.unwrap_or(false);
|
2022-10-14 08:04:38 -04:00
|
|
|
self.client_capabilities.snippet_support =
|
|
|
|
if let Some(completion) = &text_document.completion {
|
|
|
|
completion
|
|
|
|
.completion_item
|
|
|
|
.as_ref()
|
|
|
|
.and_then(|it| it.snippet_support)
|
|
|
|
.unwrap_or(false)
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
};
|
2021-04-02 02:21:07 -04:00
|
|
|
}
|
2020-12-07 05:46:39 -05:00
|
|
|
}
|
2021-05-09 21:16:04 -04:00
|
|
|
|
2022-03-20 21:33:37 -04:00
|
|
|
/// Given the configured workspaces or root URI and the their settings,
|
|
|
|
/// update and resolve any paths that should be enabled
|
2023-03-15 10:34:23 -04:00
|
|
|
pub fn update_enabled_paths(&mut self) -> bool {
|
2022-03-20 21:33:37 -04:00
|
|
|
if let Some(workspace_folders) = self.workspace_folders.clone() {
|
|
|
|
let mut touched = false;
|
2023-03-15 10:34:23 -04:00
|
|
|
for (workspace, _) in workspace_folders {
|
|
|
|
if let Some(settings) = self.settings.specifiers.get(&workspace) {
|
|
|
|
if self.update_enabled_paths_entry(
|
|
|
|
workspace,
|
|
|
|
settings.enable_paths.clone(),
|
|
|
|
) {
|
2022-03-20 21:33:37 -04:00
|
|
|
touched = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
touched
|
|
|
|
} else if let Some(root_uri) = self.root_uri.clone() {
|
|
|
|
self.update_enabled_paths_entry(
|
2023-01-26 17:24:03 -05:00
|
|
|
root_uri,
|
2022-03-20 21:33:37 -04:00
|
|
|
self.settings.workspace.enable_paths.clone(),
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Update a specific entry in the enabled paths for a given workspace.
|
|
|
|
fn update_enabled_paths_entry(
|
|
|
|
&mut self,
|
2023-01-26 17:24:03 -05:00
|
|
|
workspace: ModuleSpecifier,
|
2022-03-20 21:33:37 -04:00
|
|
|
enabled_paths: Vec<String>,
|
|
|
|
) -> bool {
|
|
|
|
let mut touched = false;
|
|
|
|
if !enabled_paths.is_empty() {
|
2022-11-28 17:28:54 -05:00
|
|
|
if let Ok(workspace_path) = specifier_to_file_path(&workspace) {
|
2022-03-20 21:33:37 -04:00
|
|
|
let mut paths = Vec::new();
|
|
|
|
for path in &enabled_paths {
|
|
|
|
let fs_path = workspace_path.join(path);
|
|
|
|
match ModuleSpecifier::from_file_path(fs_path) {
|
|
|
|
Ok(path_uri) => {
|
2023-03-15 10:34:23 -04:00
|
|
|
paths.push(path_uri);
|
2022-03-20 21:33:37 -04:00
|
|
|
}
|
|
|
|
Err(_) => {
|
|
|
|
lsp_log!("Unable to resolve a file path for `deno.enablePath` from \"{}\" for workspace \"{}\".", path, workspace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !paths.is_empty() {
|
|
|
|
touched = true;
|
2023-03-15 10:34:23 -04:00
|
|
|
self.enabled_paths.insert(workspace.clone(), paths);
|
2022-03-20 21:33:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
touched = true;
|
2023-03-15 10:34:23 -04:00
|
|
|
self.enabled_paths.remove(&workspace);
|
2022-03-20 21:33:37 -04:00
|
|
|
}
|
|
|
|
touched
|
|
|
|
}
|
|
|
|
|
2023-03-15 10:34:23 -04:00
|
|
|
pub fn get_specifiers(&self) -> Vec<ModuleSpecifier> {
|
|
|
|
self.settings.specifiers.keys().cloned().collect()
|
2021-05-09 21:16:04 -04:00
|
|
|
}
|
|
|
|
|
2022-01-25 10:30:38 -05:00
|
|
|
pub fn set_specifier_settings(
|
|
|
|
&mut self,
|
|
|
|
specifier: ModuleSpecifier,
|
|
|
|
settings: SpecifierSettings,
|
2023-03-15 10:34:23 -04:00
|
|
|
) -> bool {
|
|
|
|
if let Some(existing) = self.settings.specifiers.get(&specifier) {
|
|
|
|
if *existing == settings {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.settings.specifiers.insert(specifier, settings);
|
|
|
|
true
|
2021-05-09 21:16:04 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-10 21:03:19 -04:00
|
|
|
fn specifier_enabled(
|
|
|
|
enabled_paths: &HashMap<Url, Vec<Url>>,
|
|
|
|
excluded_paths: Option<&Vec<Url>>,
|
|
|
|
settings: &Settings,
|
|
|
|
specifier: &Url,
|
|
|
|
) -> bool {
|
|
|
|
let specifier_str = specifier.as_str();
|
|
|
|
for (workspace, enabled_paths) in enabled_paths.iter() {
|
|
|
|
if specifier_str.starts_with(workspace.as_str()) {
|
|
|
|
return enabled_paths
|
|
|
|
.iter()
|
|
|
|
.any(|path| specifier_str.starts_with(path.as_str()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let Some(excluded_paths) = excluded_paths {
|
|
|
|
for excluded_path in excluded_paths {
|
|
|
|
if specifier_str.starts_with(excluded_path.as_str()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
settings
|
|
|
|
.specifiers
|
|
|
|
.get(specifier)
|
|
|
|
.map(|settings| settings.enable)
|
|
|
|
.unwrap_or_else(|| settings.workspace.enable)
|
|
|
|
}
|
|
|
|
|
2023-07-10 17:45:09 -04:00
|
|
|
fn resolve_lockfile_from_config(
|
|
|
|
config_file: &ConfigFile,
|
|
|
|
) -> Option<Arc<Mutex<Lockfile>>> {
|
|
|
|
let lockfile_path = match config_file.resolve_lockfile_path() {
|
|
|
|
Ok(Some(value)) => value,
|
|
|
|
Ok(None) => return None,
|
|
|
|
Err(err) => {
|
|
|
|
lsp_warn!("Error resolving lockfile: {:#}", err);
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
resolve_lockfile_from_path(lockfile_path)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn resolve_node_modules_dir(config_file: &ConfigFile) -> Option<PathBuf> {
|
|
|
|
// For the language server, require an explicit opt-in via the
|
|
|
|
// `nodeModulesDir: true` setting in the deno.json file. This is to
|
|
|
|
// reduce the chance of modifying someone's node_modules directory
|
|
|
|
// without them having asked us to do so.
|
|
|
|
if config_file.node_modules_dir() != Some(true) {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
if config_file.specifier.scheme() != "file" {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
let file_path = config_file.specifier.to_file_path().ok()?;
|
|
|
|
let node_modules_dir = file_path.parent()?.join("node_modules");
|
|
|
|
canonicalize_path_maybe_not_exists(&node_modules_dir).ok()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn resolve_lockfile_from_path(
|
|
|
|
lockfile_path: PathBuf,
|
|
|
|
) -> Option<Arc<Mutex<Lockfile>>> {
|
|
|
|
match Lockfile::new(lockfile_path, false) {
|
2023-07-20 14:05:52 -04:00
|
|
|
Ok(value) => {
|
|
|
|
if let Ok(specifier) = ModuleSpecifier::from_file_path(&value.filename) {
|
|
|
|
lsp_log!(" Resolved lock file: \"{}\"", specifier);
|
|
|
|
}
|
|
|
|
Some(Arc::new(Mutex::new(value)))
|
|
|
|
}
|
2023-07-10 17:45:09 -04:00
|
|
|
Err(err) => {
|
|
|
|
lsp_warn!("Error loading lockfile: {:#}", err);
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-09 21:16:04 -04:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
use deno_core::resolve_url;
|
|
|
|
use deno_core::serde_json::json;
|
2023-04-01 15:10:30 -04:00
|
|
|
use pretty_assertions::assert_eq;
|
2021-05-09 21:16:04 -04:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_config_specifier_enabled() {
|
2022-03-20 21:33:37 -04:00
|
|
|
let mut config = Config::new();
|
2021-05-09 21:16:04 -04:00
|
|
|
let specifier = resolve_url("file:///a.ts").unwrap();
|
|
|
|
assert!(!config.specifier_enabled(&specifier));
|
|
|
|
config
|
2021-05-20 05:56:48 -04:00
|
|
|
.set_workspace_settings(json!({
|
2021-05-09 21:16:04 -04:00
|
|
|
"enable": true
|
|
|
|
}))
|
|
|
|
.expect("could not update");
|
|
|
|
assert!(config.specifier_enabled(&specifier));
|
|
|
|
}
|
2021-06-01 07:53:08 -04:00
|
|
|
|
2022-03-20 21:33:37 -04:00
|
|
|
#[test]
|
|
|
|
fn test_config_snapshot_specifier_enabled() {
|
|
|
|
let mut config = Config::new();
|
|
|
|
let specifier = resolve_url("file:///a.ts").unwrap();
|
|
|
|
assert!(!config.specifier_enabled(&specifier));
|
|
|
|
config
|
|
|
|
.set_workspace_settings(json!({
|
|
|
|
"enable": true
|
|
|
|
}))
|
|
|
|
.expect("could not update");
|
|
|
|
let config_snapshot = config.snapshot();
|
|
|
|
assert!(config_snapshot.specifier_enabled(&specifier));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_config_specifier_enabled_path() {
|
|
|
|
let mut config = Config::new();
|
|
|
|
let specifier_a = resolve_url("file:///project/worker/a.ts").unwrap();
|
|
|
|
let specifier_b = resolve_url("file:///project/other/b.ts").unwrap();
|
|
|
|
assert!(!config.specifier_enabled(&specifier_a));
|
|
|
|
assert!(!config.specifier_enabled(&specifier_b));
|
|
|
|
let mut enabled_paths = HashMap::new();
|
|
|
|
enabled_paths.insert(
|
2023-03-15 10:34:23 -04:00
|
|
|
Url::parse("file:///project/").unwrap(),
|
|
|
|
vec![Url::parse("file:///project/worker/").unwrap()],
|
2022-03-20 21:33:37 -04:00
|
|
|
);
|
|
|
|
config.enabled_paths = enabled_paths;
|
|
|
|
assert!(config.specifier_enabled(&specifier_a));
|
|
|
|
assert!(!config.specifier_enabled(&specifier_b));
|
|
|
|
let config_snapshot = config.snapshot();
|
|
|
|
assert!(config_snapshot.specifier_enabled(&specifier_a));
|
|
|
|
assert!(!config_snapshot.specifier_enabled(&specifier_b));
|
|
|
|
}
|
|
|
|
|
2021-06-01 07:53:08 -04:00
|
|
|
#[test]
|
|
|
|
fn test_set_workspace_settings_defaults() {
|
2022-03-20 21:33:37 -04:00
|
|
|
let mut config = Config::new();
|
2021-06-01 07:53:08 -04:00
|
|
|
config
|
|
|
|
.set_workspace_settings(json!({}))
|
|
|
|
.expect("could not update");
|
|
|
|
assert_eq!(
|
2023-05-11 17:17:14 -04:00
|
|
|
config.workspace_settings().clone(),
|
2021-06-01 07:53:08 -04:00
|
|
|
WorkspaceSettings {
|
|
|
|
enable: false,
|
2022-03-20 21:33:37 -04:00
|
|
|
enable_paths: Vec::new(),
|
2021-07-27 17:25:09 -04:00
|
|
|
cache: None,
|
2022-01-23 19:27:52 -05:00
|
|
|
certificate_stores: None,
|
2021-06-01 07:53:08 -04:00
|
|
|
config: None,
|
|
|
|
import_map: None,
|
|
|
|
code_lens: CodeLensSettings {
|
|
|
|
implementations: false,
|
|
|
|
references: false,
|
|
|
|
references_all_functions: false,
|
2021-06-07 07:38:07 -04:00
|
|
|
test: true,
|
2021-06-01 07:53:08 -04:00
|
|
|
},
|
2022-10-15 22:39:43 -04:00
|
|
|
inlay_hints: InlayHintsSettings {
|
|
|
|
parameter_names: InlayHintsParamNamesOptions {
|
|
|
|
enabled: InlayHintsParamNamesEnabled::None,
|
|
|
|
suppress_when_argument_matches_name: true
|
|
|
|
},
|
|
|
|
parameter_types: InlayHintsParamTypesOptions { enabled: false },
|
|
|
|
variable_types: InlayHintsVarTypesOptions {
|
|
|
|
enabled: false,
|
2022-10-28 14:48:14 -04:00
|
|
|
suppress_when_type_matches_name: true
|
2022-10-15 22:39:43 -04:00
|
|
|
},
|
|
|
|
property_declaration_types: InlayHintsPropDeclTypesOptions {
|
|
|
|
enabled: false
|
|
|
|
},
|
|
|
|
function_like_return_types: InlayHintsFuncLikeReturnTypesOptions {
|
|
|
|
enabled: false
|
|
|
|
},
|
|
|
|
enum_member_values: InlayHintsEnumMemberValuesOptions {
|
|
|
|
enabled: false
|
|
|
|
},
|
|
|
|
},
|
2021-06-01 07:53:08 -04:00
|
|
|
internal_debug: false,
|
2022-05-16 07:10:08 -04:00
|
|
|
lint: true,
|
2023-05-11 17:17:14 -04:00
|
|
|
document_preload_limit: 1_000,
|
2021-06-01 07:53:08 -04:00
|
|
|
suggest: CompletionSettings {
|
|
|
|
complete_function_calls: false,
|
|
|
|
names: true,
|
|
|
|
paths: true,
|
|
|
|
auto_imports: true,
|
|
|
|
imports: ImportCompletionSettings {
|
|
|
|
auto_discover: true,
|
|
|
|
hosts: HashMap::new(),
|
|
|
|
}
|
|
|
|
},
|
2022-03-29 18:59:27 -04:00
|
|
|
testing: TestingSettings {
|
|
|
|
args: vec!["--allow-all".to_string(), "--no-check".to_string()],
|
|
|
|
enable: true
|
|
|
|
},
|
2022-01-23 19:27:52 -05:00
|
|
|
tls_certificate: None,
|
|
|
|
unsafely_ignore_certificate_errors: None,
|
2021-06-01 07:53:08 -04:00
|
|
|
unstable: false,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2023-01-03 10:59:48 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_empty_cache() {
|
|
|
|
let mut config = Config::new();
|
|
|
|
config
|
|
|
|
.set_workspace_settings(json!({ "cache": "" }))
|
|
|
|
.expect("could not update");
|
|
|
|
assert_eq!(
|
2023-05-11 17:17:14 -04:00
|
|
|
config.workspace_settings().clone(),
|
2023-01-03 10:59:48 -05:00
|
|
|
WorkspaceSettings::default()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_empty_import_map() {
|
|
|
|
let mut config = Config::new();
|
|
|
|
config
|
|
|
|
.set_workspace_settings(json!({ "import_map": "" }))
|
|
|
|
.expect("could not update");
|
|
|
|
assert_eq!(
|
2023-05-11 17:17:14 -04:00
|
|
|
config.workspace_settings().clone(),
|
2023-01-03 10:59:48 -05:00
|
|
|
WorkspaceSettings::default()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_empty_tls_certificate() {
|
|
|
|
let mut config = Config::new();
|
|
|
|
config
|
|
|
|
.set_workspace_settings(json!({ "tls_certificate": "" }))
|
|
|
|
.expect("could not update");
|
|
|
|
assert_eq!(
|
2023-05-11 17:17:14 -04:00
|
|
|
config.workspace_settings().clone(),
|
2023-01-03 10:59:48 -05:00
|
|
|
WorkspaceSettings::default()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_empty_config() {
|
|
|
|
let mut config = Config::new();
|
|
|
|
config
|
|
|
|
.set_workspace_settings(json!({ "config": "" }))
|
|
|
|
.expect("could not update");
|
|
|
|
assert_eq!(
|
2023-05-11 17:17:14 -04:00
|
|
|
config.workspace_settings().clone(),
|
2023-01-03 10:59:48 -05:00
|
|
|
WorkspaceSettings::default()
|
|
|
|
);
|
|
|
|
}
|
2023-03-30 17:47:53 -04:00
|
|
|
|
|
|
|
#[test]
|
2023-04-01 15:10:30 -04:00
|
|
|
fn config_enabled_urls() {
|
2023-03-30 17:47:53 -04:00
|
|
|
let mut config = Config::new();
|
|
|
|
let root_dir = Url::parse("file:///example/").unwrap();
|
|
|
|
config.root_uri = Some(root_dir.clone());
|
|
|
|
config.settings.workspace.enable = false;
|
|
|
|
config.settings.workspace.enable_paths = Vec::new();
|
2023-04-01 15:10:30 -04:00
|
|
|
assert_eq!(config.enabled_urls(), vec![]);
|
2023-03-30 17:47:53 -04:00
|
|
|
|
|
|
|
config.settings.workspace.enable = true;
|
2023-04-01 15:10:30 -04:00
|
|
|
assert_eq!(config.enabled_urls(), vec![root_dir]);
|
2023-03-30 17:47:53 -04:00
|
|
|
|
|
|
|
config.settings.workspace.enable = false;
|
|
|
|
let root_dir1 = Url::parse("file:///root1/").unwrap();
|
|
|
|
let root_dir2 = Url::parse("file:///root2/").unwrap();
|
|
|
|
let root_dir3 = Url::parse("file:///root3/").unwrap();
|
|
|
|
config.enabled_paths = HashMap::from([
|
|
|
|
(
|
|
|
|
root_dir1.clone(),
|
|
|
|
vec![
|
2023-04-01 15:10:30 -04:00
|
|
|
root_dir1.join("sub_dir/").unwrap(),
|
|
|
|
root_dir1.join("sub_dir/other/").unwrap(),
|
2023-03-30 17:47:53 -04:00
|
|
|
root_dir1.join("test.ts").unwrap(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
(root_dir2.clone(), vec![root_dir2.join("other.ts").unwrap()]),
|
|
|
|
(root_dir3.clone(), vec![]),
|
|
|
|
]);
|
|
|
|
|
|
|
|
assert_eq!(
|
2023-04-01 15:10:30 -04:00
|
|
|
config.enabled_urls(),
|
2023-03-30 17:47:53 -04:00
|
|
|
vec![
|
2023-04-01 15:10:30 -04:00
|
|
|
root_dir1.join("sub_dir/").unwrap(),
|
|
|
|
root_dir1.join("sub_dir/other/").unwrap(),
|
2023-03-30 17:47:53 -04:00
|
|
|
root_dir1.join("test.ts").unwrap(),
|
|
|
|
root_dir2.join("other.ts").unwrap(),
|
|
|
|
root_dir3
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
2020-12-07 05:46:39 -05:00
|
|
|
}
|