-
Notifications
You must be signed in to change notification settings - Fork 290
[typespec-vscode] Allow lsp disable running emitters #7576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mzhongl524
merged 64 commits into
microsoft:main
from
mzhongl524:allow-lsp-disable-running-emitters
Jun 19, 2025
Merged
Changes from 60 commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
b0ac596
Merge pull request #1 from microsoft/main
mzhongl524 3fcbe52
Merge branch 'microsoft:main' into main
mzhongl524 c109816
Merge branch 'microsoft:main' into main
mzhongl524 23f0108
Merge branch 'microsoft:main' into main
mzhongl524 6f04f65
Merge branch 'microsoft:main' into main
mzhongl524 688ca03
Merge branch 'microsoft:main' into main
mzhongl524 de3725e
Merge branch 'microsoft:main' into main
mzhongl524 8130ffb
Merge branch 'microsoft:main' into main
mzhongl524 beb6433
Merge branch 'microsoft:main' into main
mzhongl524 8a501f2
Merge branch 'microsoft:main' into main
mzhongl524 6e1ab2d
Merge branch 'microsoft:main' into main
mzhongl524 a35052f
Merge branch 'microsoft:main' into main
mzhongl524 be57c13
Merge branch 'microsoft:main' into main
mzhongl524 3a9dc7a
Merge branch 'microsoft:main' into main
mzhongl524 ad7dff7
Merge branch 'microsoft:main' into main
mzhongl524 f8e8f2f
Merge branch 'microsoft:main' into main
mzhongl524 7a700c8
Merge branch 'microsoft:main' into main
mzhongl524 5099583
Merge branch 'microsoft:main' into main
mzhongl524 a45dbd5
Merge branch 'microsoft:main' into main
mzhongl524 68cc91d
Merge branch 'microsoft:main' into main
mzhongl524 48a44ad
Merge branch 'microsoft:main' into main
mzhongl524 b9283c4
Merge branch 'microsoft:main' into main
mzhongl524 4286411
Merge branch 'microsoft:main' into main
mzhongl524 e549035
Merge branch 'microsoft:main' into main
mzhongl524 9717310
Merge branch 'microsoft:main' into main
mzhongl524 75260f8
Merge branch 'microsoft:main' into main
mzhongl524 18b1595
Merge branch 'microsoft:main' into main
mzhongl524 51078a7
Merge branch 'microsoft:main' into main
mzhongl524 75ae17a
Merge branch 'microsoft:main' into main
mzhongl524 da28d95
Merge branch 'microsoft:main' into main
mzhongl524 4afbb98
Merge branch 'microsoft:main' into main
mzhongl524 463bdd5
Merge branch 'microsoft:main' into main
mzhongl524 c105d86
Merge branch 'microsoft:main' into main
mzhongl524 39dc63e
Merge branch 'microsoft:main' into main
mzhongl524 ddb0c11
Merge branch 'microsoft:main' into main
mzhongl524 dccb3dc
Merge branch 'microsoft:main' into main
mzhongl524 af9903b
Merge branch 'microsoft:main' into main
mzhongl524 2dddaf5
Merge branch 'microsoft:main' into main
mzhongl524 857b72b
Merge branch 'microsoft:main' into main
mzhongl524 41f34d9
Merge branch 'microsoft:main' into main
mzhongl524 f4dd38f
Merge branch 'microsoft:main' into main
mzhongl524 4fd48e5
Merge branch 'microsoft:main' into main
mzhongl524 9870818
Merge branch 'microsoft:main' into main
mzhongl524 9bf8cdc
Merge branch 'microsoft:main' into main
mzhongl524 d596efd
Merge branch 'microsoft:main' into main
mzhongl524 aed33c0
Merge branch 'microsoft:main' into main
mzhongl524 6b49c4b
Merge branch 'microsoft:main' into main
mzhongl524 6687f5c
Merge branch 'microsoft:main' into main
mzhongl524 10aa654
Merge branch 'microsoft:main' into main
mzhongl524 fbf956e
Merge branch 'microsoft:main' into main
mzhongl524 0e3d44d
Merge branch 'microsoft:main' into main
mzhongl524 6586a10
Merge branch 'microsoft:main' into main
mzhongl524 5920ad3
Merge branch 'microsoft:main' into main
mzhongl524 2ece297
Merge branch 'microsoft:main' into main
mzhongl524 4ad5c5b
Merge branch 'microsoft:main' into main
mzhongl524 11fd24f
Merge branch 'microsoft:main' into main
mzhongl524 f15e07c
Merge branch 'microsoft:main' into main
mzhongl524 7661273
Allow LSP to disable running emitters
mzhongl524 b43717a
updated
mzhongl524 4e395a0
updated
mzhongl524 2a9bb56
updated
mzhongl524 64975d6
updated
mzhongl524 23ab58b
Create allow-lsp-disable-running-emitters-2025-5-11-2-18-42.md
mzhongl524 a5419df
updated
mzhongl524 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,140 @@ | ||
import { Connection, DidChangeConfigurationNotification } from "vscode-languageserver/node.js"; | ||
import { ServerHost } from "./types.js"; | ||
|
||
/** | ||
* Represents configuration value with additional metadata | ||
*/ | ||
export interface ConfigurationValue<T = any> { | ||
/** The configuration value */ | ||
value: T; | ||
/** The scope where this value was defined (global, workspace, etc.) */ | ||
scope?: "default" | "global" | "workspace" | "workspaceFolder"; | ||
/** Language specific configuration if applicable */ | ||
languageId?: string; | ||
} | ||
|
||
/** | ||
* TypeSpec client-side configuration provider | ||
* Inspired by VS Code's WorkspaceConfiguration API for extensibility | ||
*/ | ||
export interface ClientConfigProvider { | ||
/** | ||
* Get a configuration value by section key | ||
* @param section The configuration section (e.g., "lsp.emit", "formatting.enabled") | ||
* @param defaultValue Default value if not found | ||
* @returns The configuration value or default | ||
*/ | ||
get<T>(section: string): T | undefined; | ||
get<T>(section: string, defaultValue: T): T; | ||
|
||
/** | ||
* Check if a configuration section exists | ||
* @param section The configuration section | ||
* @returns True if the section exists | ||
*/ | ||
has(section: string): boolean; | ||
|
||
/** | ||
* Get detailed information about a configuration value | ||
* @param section The configuration section | ||
* @returns Detailed configuration information | ||
*/ | ||
inspect<T>(section: string): ConfigurationValue<T> | undefined; | ||
|
||
/** | ||
* Update the entire configuration | ||
* @param configs The new configuration object | ||
*/ | ||
update(configs: Record<string, any>): void; | ||
|
||
/** | ||
* Initialize client configuration with connection and host | ||
* @param connection Language server connection | ||
* @param host Server host instance | ||
*/ | ||
initialize(connection: Connection, host: ServerHost): Promise<void>; | ||
} | ||
|
||
export function createClientConfigProvider(): ClientConfigProvider { | ||
let configuration: Record<string, any> = {}; | ||
|
||
function get<T>(section: string): T | undefined; | ||
function get<T>(section: string, defaultValue: T): T; | ||
function get<T>(section: string, defaultValue?: T): T | undefined { | ||
const keys = section.split("."); | ||
let current: any = configuration; | ||
|
||
for (const key of keys) { | ||
if (current && typeof current === "object" && key in current) { | ||
current = current[key]; | ||
} else { | ||
return defaultValue; | ||
} | ||
} | ||
|
||
return current !== undefined ? current : defaultValue; | ||
} | ||
|
||
function has(section: string): boolean { | ||
const keys = section.split("."); | ||
let current: any = configuration; | ||
|
||
for (const key of keys) { | ||
if (current && typeof current === "object" && key in current) { | ||
current = current[key]; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
return current !== undefined; | ||
} | ||
|
||
function inspect<T>(section: string): ConfigurationValue<T> | undefined { | ||
if (!has(section)) { | ||
return undefined; | ||
} | ||
|
||
const value = get<T>(section); | ||
return { | ||
value: value as T, // Safe cast since we know it exists from has() check | ||
scope: "workspace", // Default scope, could be enhanced to track actual scope | ||
}; | ||
} | ||
|
||
function update(configs: Record<string, any>): void { | ||
configuration = { ...configs }; | ||
} | ||
|
||
async function initialize(connection: Connection, host: ServerHost): Promise<void> { | ||
try { | ||
await connection.client.register(DidChangeConfigurationNotification.type, undefined); | ||
mzhongl524 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const configs = await connection.workspace.getConfiguration("typespec"); | ||
host.log({ level: "debug", message: "VSCode settings loaded", detail: configs }); | ||
|
||
update(configs); | ||
|
||
connection.onDidChangeConfiguration(async (params) => { | ||
if (params.settings && params.settings.typespec) { | ||
mzhongl524 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
update(params.settings.typespec); | ||
} | ||
|
||
host.log({ level: "debug", message: "Configuration changed", detail: params.settings }); | ||
}); | ||
} catch (error) { | ||
host.log({ | ||
level: "error", | ||
message: "An error occurred while loading the VSCode settings", | ||
detail: error, | ||
}); | ||
} | ||
} | ||
|
||
return { | ||
get, | ||
has, | ||
inspect, | ||
update, | ||
initialize, | ||
}; | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.