-
Notifications
You must be signed in to change notification settings - Fork 5
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
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
- Loading branch information
1 parent
5446d7e
commit cb98410
Showing
14 changed files
with
406 additions
and
11 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,53 @@ | ||
use serde::Deserialize; | ||
use serde_json::Value; | ||
use url::Url; | ||
|
||
// These settings are only needed once, typically for initialization. | ||
// They are read at the global scope on the client side and are never refreshed. | ||
#[derive(Debug, Deserialize, Default, Clone)] | ||
#[cfg_attr(test, derive(PartialEq, Eq))] | ||
#[serde(rename_all = "camelCase")] | ||
pub(crate) struct ClientGlobalSettings { | ||
pub(crate) log_level: Option<crate::logging::LogLevel>, | ||
pub(crate) dependency_log_levels: Option<String>, | ||
} | ||
|
||
/// This is a direct representation of the user level settings schema sent | ||
/// by the client. It is refreshed after configuration changes. | ||
#[derive(Debug, Deserialize, Default, Clone)] | ||
#[cfg_attr(test, derive(PartialEq, Eq))] | ||
#[serde(rename_all = "camelCase")] | ||
pub(crate) struct ClientSettings {} | ||
|
||
/// This is a direct representation of the workspace level settings schema sent by the | ||
/// client. It is the same as the user level settings with the addition of the workspace | ||
/// path. | ||
#[derive(Debug, Deserialize)] | ||
#[cfg_attr(test, derive(PartialEq, Eq))] | ||
#[serde(rename_all = "camelCase")] | ||
pub(crate) struct ClientWorkspaceSettings { | ||
pub(crate) url: Url, | ||
#[serde(flatten)] | ||
pub(crate) settings: ClientSettings, | ||
} | ||
|
||
/// This is the exact schema for initialization options sent in by the client | ||
/// during initialization. | ||
#[derive(Debug, Deserialize, Default)] | ||
#[cfg_attr(test, derive(PartialEq, Eq))] | ||
#[serde(rename_all = "camelCase")] | ||
pub(crate) struct InitializationOptions { | ||
pub(crate) global_settings: ClientGlobalSettings, | ||
pub(crate) user_settings: ClientSettings, | ||
pub(crate) workspace_settings: Vec<ClientWorkspaceSettings>, | ||
} | ||
|
||
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 client 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This directory contains "common" utilities used across language server extensions. | ||
|
||
They are pulled directly from this MIT licensed repo: | ||
https://github.com/microsoft/vscode-python-tools-extension-template |
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,12 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// https://github.com/microsoft/vscode-python-tools-extension-template | ||
|
||
import * as path from "path"; | ||
|
||
const folderName = path.basename(__dirname); | ||
|
||
export const EXTENSION_ROOT_DIR = | ||
folderName === "common" | ||
? path.dirname(path.dirname(__dirname)) | ||
: path.dirname(__dirname); |
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,29 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// https://github.com/microsoft/vscode-python-tools-extension-template | ||
|
||
import * as util from "util"; | ||
import { Disposable, OutputChannel } from "vscode"; | ||
|
||
type Arguments = unknown[]; | ||
class OutputChannelLogger { | ||
constructor(private readonly channel: OutputChannel) {} | ||
|
||
public traceLog(...data: Arguments): void { | ||
this.channel.appendLine(util.format(...data)); | ||
} | ||
} | ||
|
||
let channel: OutputChannelLogger | undefined; | ||
export function registerLogger(outputChannel: OutputChannel): Disposable { | ||
channel = new OutputChannelLogger(outputChannel); | ||
return { | ||
dispose: () => { | ||
channel = undefined; | ||
}, | ||
}; | ||
} | ||
|
||
export function traceLog(...args: Arguments): void { | ||
channel?.traceLog(...args); | ||
} |
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,19 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// https://github.com/microsoft/vscode-python-tools-extension-template | ||
|
||
import * as path from "path"; | ||
import * as fs from "fs-extra"; | ||
import { EXTENSION_ROOT_DIR } from "./constants"; | ||
|
||
export interface IServerInfo { | ||
name: string; | ||
module: string; | ||
} | ||
|
||
export function loadServerDefaults(): IServerInfo { | ||
const packageJson = path.join(EXTENSION_ROOT_DIR, "package.json"); | ||
const content = fs.readFileSync(packageJson).toString(); | ||
const config = JSON.parse(content); | ||
return config.serverInfo as IServerInfo; | ||
} |
Oops, something went wrong.