mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 02:28:34 +01:00
editable tool input (#244108)
* support to dynamically register JSON schema association * support to dispose schema and association registration * hook up schema, associations, and documents when reviewing tool input
This commit is contained in:
@@ -182,7 +182,7 @@ export async function startClient(context: ExtensionContext, newLanguageClient:
|
||||
};
|
||||
}
|
||||
|
||||
async function startClientWithParticipants(context: ExtensionContext, languageParticipants: LanguageParticipants, newLanguageClient: LanguageClientConstructor, runtime: Runtime): Promise<AsyncDisposable> {
|
||||
async function startClientWithParticipants(_context: ExtensionContext, languageParticipants: LanguageParticipants, newLanguageClient: LanguageClientConstructor, runtime: Runtime): Promise<AsyncDisposable> {
|
||||
|
||||
const toDispose: Disposable[] = [];
|
||||
|
||||
@@ -495,10 +495,19 @@ async function startClientWithParticipants(context: ExtensionContext, languagePa
|
||||
|
||||
toDispose.push(commands.registerCommand('_json.retryResolveSchema', handleRetryResolveSchemaCommand));
|
||||
|
||||
client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociations(context));
|
||||
client.sendNotification(SchemaAssociationNotification.type, await getSchemaAssociations());
|
||||
|
||||
toDispose.push(extensions.onDidChange(_ => {
|
||||
client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociations(context));
|
||||
toDispose.push(extensions.onDidChange(async _ => {
|
||||
client.sendNotification(SchemaAssociationNotification.type, await getSchemaAssociations());
|
||||
}));
|
||||
|
||||
const associationWatcher = workspace.createFileSystemWatcher(new RelativePattern(
|
||||
Uri.parse(`vscode://schemas-associations/`),
|
||||
'**/schemas-associations.json')
|
||||
);
|
||||
toDispose.push(associationWatcher);
|
||||
toDispose.push(associationWatcher.onDidChange(async _e => {
|
||||
client.sendNotification(SchemaAssociationNotification.type, await getSchemaAssociations());
|
||||
}));
|
||||
|
||||
// manually register / deregister format provider based on the `json.format.enable` setting avoiding issues with late registration. See #71652.
|
||||
@@ -595,7 +604,12 @@ async function startClientWithParticipants(context: ExtensionContext, languagePa
|
||||
};
|
||||
}
|
||||
|
||||
function getSchemaAssociations(_context: ExtensionContext): ISchemaAssociation[] {
|
||||
async function getSchemaAssociations(): Promise<ISchemaAssociation[]> {
|
||||
return getSchemaExtensionAssociations()
|
||||
.concat(await getDynamicSchemaAssociations());
|
||||
}
|
||||
|
||||
function getSchemaExtensionAssociations(): ISchemaAssociation[] {
|
||||
const associations: ISchemaAssociation[] = [];
|
||||
extensions.allAcrossExtensionHosts.forEach(extension => {
|
||||
const packageJSON = extension.packageJSON;
|
||||
@@ -631,6 +645,24 @@ function getSchemaAssociations(_context: ExtensionContext): ISchemaAssociation[]
|
||||
return associations;
|
||||
}
|
||||
|
||||
async function getDynamicSchemaAssociations(): Promise<ISchemaAssociation[]> {
|
||||
const result: ISchemaAssociation[] = [];
|
||||
try {
|
||||
const data = await workspace.fs.readFile(Uri.parse(`vscode://schemas-associations/schemas-associations.json`));
|
||||
const rawStr = new TextDecoder().decode(data);
|
||||
const obj = <Record<string, string[]>>JSON.parse(rawStr);
|
||||
for (const item of Object.keys(obj)) {
|
||||
result.push({
|
||||
fileMatch: obj[item],
|
||||
uri: item
|
||||
});
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function getSettings(): Settings {
|
||||
const configuration = workspace.getConfiguration();
|
||||
const httpSettings = workspace.getConfiguration('http');
|
||||
|
||||
Reference in New Issue
Block a user