Skip to content

Commit 4ade580

Browse files
committed
Codelens for referenced grammars
See eclipse-lemminx/lemminx#1092 Signed-off-by: azerr <azerr@redhat.com>
1 parent e903708 commit 4ade580

File tree

3 files changed

+48
-27
lines changed

3 files changed

+48
-27
lines changed

src/client/xmlClient.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ function getLanguageClientOptions(logfile: string, externalXmlSettings: External
124124
codeLensKind: {
125125
valueSet: [
126126
'references',
127-
'association'
127+
'association',
128+
'open.uri'
128129
]
129130
}
130131
},

src/commands/commandConstants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ export namespace ClientCommandConstants {
3737
*/
3838
export const OPEN_SETTINGS = 'xml.open.settings';
3939

40+
/**
41+
* Open settings command
42+
*
43+
* A `settingId: string` parameter can be optionally provided
44+
*/
45+
export const OPEN_URI = 'xml.open.uri';
46+
4047
/**
4148
* Render markdown string to html string
4249
*/

src/commands/registerCommands.ts

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ClientCommandConstants, ServerCommandConstants } from "./commandConstan
1313
export function registerClientOnlyCommands(context: ExtensionContext) {
1414
registerDocsCommands(context);
1515
registerOpenSettingsCommand(context);
16+
registerOpenUriCommand(context);
1617
}
1718

1819
/**
@@ -41,7 +42,8 @@ export async function registerClientServerCommands(context: ExtensionContext, la
4142
};
4243
if (token) {
4344
return languageClient.sendRequest(ExecuteCommandRequest.type, params, token);
44-
} else {
45+
}
46+
else {
4547
return languageClient.sendRequest(ExecuteCommandRequest.type, params);
4648
}
4749
}));
@@ -81,6 +83,17 @@ function registerOpenSettingsCommand(context: ExtensionContext) {
8183
}));
8284
}
8385

86+
/**
87+
* Registers a command that opens the settings page to a given setting
88+
*
89+
* @param context the extension context
90+
*/
91+
function registerOpenUriCommand(context: ExtensionContext) {
92+
context.subscriptions.push(commands.registerCommand(ClientCommandConstants.OPEN_URI, async (uri?: string) => {
93+
commands.executeCommand('vscode.open', Uri.parse(uri));
94+
}));
95+
}
96+
8497
/**
8598
* Register commands used for code lens "references"
8699
*
@@ -144,12 +157,12 @@ for (const label of bindingTypes.keys()) {
144157
* @param uri the uri of the XML file path
145158
* @param languageClient the language server client
146159
*/
147-
async function grammarAssociationCommand (documentURI: Uri, languageClient: LanguageClient) {
160+
async function grammarAssociationCommand(documentURI: Uri, languageClient: LanguageClient) {
148161
// A click on Bind to grammar/schema... has been processed in the XML document which is not bound to a grammar
149162

150163
// Step 1 : open a combo to select the binding type ("standard", "xml-model")
151164
const pickedBindingTypeOption = await window.showQuickPick(bindingTypeOptions, { placeHolder: "Binding type" });
152-
if(!pickedBindingTypeOption) {
165+
if (!pickedBindingTypeOption) {
153166
return;
154167
}
155168
const bindingType = bindingTypes.get(pickedBindingTypeOption.label);
@@ -190,7 +203,7 @@ async function grammarAssociationCommand (documentURI: Uri, languageClient: Lang
190203
* @param context the extension context
191204
* @param languageClient the language server client
192205
*/
193-
function registerAssociationCommands(context: ExtensionContext, languageClient: LanguageClient) {
206+
function registerAssociationCommands(context: ExtensionContext, languageClient: LanguageClient) {
194207
// For CodeLens
195208
context.subscriptions.push(commands.registerCommand(ClientCommandConstants.OPEN_BINDING_WIZARD, async (uriString: string) => {
196209
const uri = Uri.parse(uriString);
@@ -208,25 +221,25 @@ async function grammarAssociationCommand (documentURI: Uri, languageClient: Lang
208221
}
209222
}));
210223

211-
}
212-
213-
/**
214-
* Change value of 'canBindGrammar' to determine if grammar/schema can be bound
215-
*
216-
* @param document the text document
217-
* @returns the `hasGrammar` check result from server
218-
*/
219-
async function checkCanBindGrammar(documentURI: Uri) {
220-
// Retrieve the document uri and identifier
221-
const identifier = TextDocumentIdentifier.create(documentURI.toString());
222-
223-
// Set the custom condition to watch if file already has bound grammar
224-
var result = false;
225-
try {
226-
result = await commands.executeCommand(ServerCommandConstants.CHECK_BOUND_GRAMMAR, identifier);
227-
} catch(error) {
228-
console.log(`Error while checking bound grammar : ${error}`);
229-
}
230-
231-
return result
232-
}
224+
}
225+
226+
/**
227+
* Change value of 'canBindGrammar' to determine if grammar/schema can be bound
228+
*
229+
* @param document the text document
230+
* @returns the `hasGrammar` check result from server
231+
*/
232+
async function checkCanBindGrammar(documentURI: Uri) {
233+
// Retrieve the document uri and identifier
234+
const identifier = TextDocumentIdentifier.create(documentURI.toString());
235+
236+
// Set the custom condition to watch if file already has bound grammar
237+
var result = false;
238+
try {
239+
result = await commands.executeCommand(ServerCommandConstants.CHECK_BOUND_GRAMMAR, identifier);
240+
} catch (error) {
241+
console.log(`Error while checking bound grammar : ${error}`);
242+
}
243+
244+
return result
245+
}

0 commit comments

Comments
 (0)