-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send structured
InitializationOptions
to the server (#121)
* Send structured `InitializationOptions` to the server In particular, this lets us respect `air.logLevel` and `air.dependencyLogLevels` on server startup User and workspace level settings are not used yet but are included for completeness * Only send over `logLevel` and `dependencyLogLevels` as flat initialization options * Remove unused cfg-attr * Simplify `InitializationOptions` creation * No need for `async`, and don't use interfacing naming
- Loading branch information
1 parent
5446d7e
commit 92887d3
Showing
9 changed files
with
167 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use serde::Deserialize; | ||
use serde_json::Value; | ||
|
||
/// This is the exact schema for initialization options sent in by the client | ||
/// during initialization. Remember that initialization options are ones that are | ||
/// strictly required at startup time, and most configuration options should really be | ||
/// "pulled" dynamically by the server after startup and whenever we receive a | ||
/// configuration change notification (#121). | ||
#[derive(Debug, Deserialize, Default)] | ||
#[serde(rename_all = "camelCase")] | ||
pub(crate) struct InitializationOptions { | ||
pub(crate) log_level: Option<crate::logging::LogLevel>, | ||
pub(crate) dependency_log_levels: Option<String>, | ||
} | ||
|
||
impl InitializationOptions { | ||
pub(crate) fn from_value(value: Value) -> Self { | ||
serde_json::from_value(value) | ||
.map_err(|err| { | ||
tracing::error!("Failed to deserialize initialization options: {err}. Falling back to default settings."); | ||
}) | ||
.unwrap_or_default() | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { ConfigurationScope, workspace, WorkspaceConfiguration } from "vscode"; | ||
|
||
type LogLevel = "error" | "warn" | "info" | "debug" | "trace"; | ||
|
||
// This is a direct representation of the Client settings sent to the Server in the | ||
// `initializationOptions` field of `InitializeParams`. These are only pulled at the | ||
// user level since they are global settings on the server side (and are scoped to | ||
// `"scope": "application"` in `package.json` so they can't even be set at workspace level). | ||
export type InitializationOptions = { | ||
logLevel?: LogLevel; | ||
dependencyLogLevels?: string; | ||
}; | ||
|
||
export function getInitializationOptions( | ||
namespace: string | ||
): InitializationOptions { | ||
const config = getConfiguration(namespace); | ||
|
||
return { | ||
logLevel: getOptionalUserValue<LogLevel>(config, "logLevel"), | ||
dependencyLogLevels: getOptionalUserValue<string>( | ||
config, | ||
"dependencyLogLevels" | ||
), | ||
}; | ||
} | ||
|
||
function getOptionalUserValue<T>( | ||
config: WorkspaceConfiguration, | ||
key: string | ||
): T | undefined { | ||
const inspect = config.inspect<T>(key); | ||
return inspect?.globalValue; | ||
} | ||
|
||
function getConfiguration( | ||
config: string, | ||
scope?: ConfigurationScope | ||
): WorkspaceConfiguration { | ||
return workspace.getConfiguration(config, scope); | ||
} |