Repository navigation
Support scoped workspace/configuration with scopeUri for per-document-settings #1178
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { Event, EventEmitter, extensions } from 'vscode'; | ||
| import { Event, EventEmitter, extensions, workspace } from 'vscode'; | ||
| import { DocumentFilter, DocumentSelector } from 'vscode-languageclient'; | ||
|
|
||
| const SCHEMES: string[] = [ | ||
|
|
@@ -57,6 +57,17 @@ export function getLanguageParticipants(): LanguageParticipants { | |
| } | ||
| } | ||
| } | ||
|
|
||
| const settingParticipants = workspace.getConfiguration('xml').get<string[]>('languageParticipants', []); | ||
| if (!Array.isArray(settingParticipants)) { | ||
| return !isEqualSet(languages, oldLanguages); | ||
| } | ||
| for (const languageId of settingParticipants) { | ||
| if (typeof languageId === 'string') { | ||
| languages.add(languageId); | ||
| } | ||
| } | ||
|
|
||
| return !isEqualSet(languages, oldLanguages); | ||
| } | ||
| update(); | ||
|
|
@@ -67,6 +78,14 @@ export function getLanguageParticipants(): LanguageParticipants { | |
| } | ||
| }); | ||
|
|
||
| const configListener = workspace.onDidChangeConfiguration(e => { | ||
| if (e.affectsConfiguration('xml.languageParticipants')) { | ||
| if (update()) { | ||
| onDidChangeEmmiter.fire(); | ||
|
Comment on lines
+81
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Reconfigure the client when language participants change.
Subscribe the client to 🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
| }); | ||
|
|
||
| return { | ||
| onDidChange: onDidChangeEmmiter.event, | ||
| get documentSelector() { | ||
|
|
@@ -80,7 +99,7 @@ export function getLanguageParticipants(): LanguageParticipants { | |
| }); | ||
| }, | ||
| hasLanguage(languageId: string) { return languages.has(languageId); }, | ||
| dispose: () => changeListener.dispose() | ||
| dispose: () => { changeListener.dispose(); configListener.dispose(); } | ||
| }; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ | |
| return l as string; | ||
| }); | ||
|
|
||
| const ExecuteClientCommandRequest: RequestType<ExecuteCommandParams, any, void> = new RequestType('xml/executeClientCommand'); | ||
|
Check warning on line 29 in src/client/xmlClient.ts
|
||
|
|
||
| interface AutoInsertParams { | ||
| kind: 'autoQuote' | 'autoClose'; | ||
|
|
@@ -34,12 +34,12 @@ | |
| position: { line: number; character: number }; | ||
| } | ||
|
|
||
| const AutoInsertRequest: RequestType<AutoInsertParams, AutoInsertResult, any> = new RequestType('xml/autoInsert'); | ||
|
Check warning on line 37 in src/client/xmlClient.ts
|
||
|
|
||
| interface ActionableMessage { | ||
| severity: MessageType; | ||
| message: string; | ||
| data?: any; | ||
|
Check warning on line 42 in src/client/xmlClient.ts
|
||
| commands?: Command[]; | ||
| } | ||
|
|
||
|
|
@@ -103,20 +103,33 @@ | |
| })); | ||
| } | ||
|
|
||
| // Copied from: | ||
| // https://github.com/redhat-developer/vscode-java/pull/1081/files | ||
| languageClient.onRequest(ConfigurationRequest.type, (params: ConfigurationParams) => { | ||
| const result: any[] = []; | ||
|
Check warning on line 107 in src/client/xmlClient.ts
|
||
| const activeEditor: TextEditor | undefined = window.activeTextEditor; | ||
| for (const item of params.items) { | ||
| if (activeEditor && activeEditor.document.uri.toString() === Uri.parse(item.scopeUri).toString()) { | ||
| if (item.section === "xml.format.insertSpaces") { | ||
| result.push(activeEditor.options.insertSpaces); | ||
| } else if (item.section === "xml.format.tabSize") { | ||
| result.push(activeEditor.options.tabSize); | ||
| const scopeUri = item.scopeUri ? Uri.parse(item.scopeUri) : undefined; | ||
| const isActiveDocument = activeEditor && scopeUri | ||
| && activeEditor.document.uri.toString() === scopeUri.toString(); | ||
| if (isActiveDocument && item.section === "xml.format.insertSpaces") { | ||
| result.push(activeEditor.options.insertSpaces); | ||
| } else if (isActiveDocument && item.section === "xml.format.tabSize") { | ||
| result.push(activeEditor.options.tabSize); | ||
| } else if (scopeUri) { | ||
| const doc = workspace.textDocuments.find( | ||
| d => d.uri.toString() === scopeUri.toString()); | ||
| const scope = doc | ||
| ? { uri: scopeUri, languageId: doc.languageId } | ||
| : scopeUri; | ||
| if (!item.section) { | ||
| result.push(workspace.getConfiguration(undefined, scope)); | ||
| } else { | ||
| const lastDot = item.section.lastIndexOf('.'); | ||
| const sectionPrefix = lastDot > 0 ? item.section.substring(0, lastDot) : undefined; | ||
| const key = lastDot > 0 ? item.section.substring(lastDot + 1) : item.section; | ||
| result.push(workspace.getConfiguration(sectionPrefix, scope).get(key)); | ||
| } | ||
| } else { | ||
| result.push(workspace.getConfiguration(null, Uri.parse(item.scopeUri)).get(item.section)); | ||
| result.push(workspace.getConfiguration().get(item.section)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win Return the full configuration for an unscoped item without a section. If a configuration item omits both 🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
| return result; | ||
|
|
@@ -131,7 +144,7 @@ | |
| } | ||
| })); | ||
|
|
||
| const onDidGrantWorkspaceTrust = (workspace as any).onDidGrantWorkspaceTrust; | ||
|
Check warning on line 147 in src/client/xmlClient.ts
|
||
| if (onDidGrantWorkspaceTrust !== undefined) { | ||
| context.subscriptions.push(onDidGrantWorkspaceTrust(() => { | ||
| languageClient.sendNotification(DidChangeConfigurationNotification.type, { settings: getXMLSettings(requirementsData.java_home, logfile, externalXmlSettings) }); | ||
|
|
@@ -207,7 +220,7 @@ | |
| show(notification.message, ...titles).then((selection) => { | ||
| for (const action of notification.commands) { | ||
| if (action.title === selection) { | ||
| const args: any[] = (action.arguments) ? action.arguments : []; | ||
|
Check warning on line 223 in src/client/xmlClient.ts
|
||
| commands.executeCommand(action.command, ...args); | ||
| break; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Guard against a non-array setting value.
get<string[]>returns the raw user value, and VS Code does not enforce the schema type at runtime. If a user setsxml.languageParticipantsto a string or object,for...ofcan throw. A string value would add single characters as language IDs. An object throws aTypeError. The exception propagates out ofupdate()during initial setup, and out of the configuration listener later. CheckArray.isArrayfirst.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents