Skip to content

Commit

Permalink
XSD CodeLens references should be clickable
Browse files Browse the repository at this point in the history
Fix eclipse-lemminx/lemminx#490

This PR bind the XSD CodeLens references command to a function which
opens the vscode references.
  • Loading branch information
angelozerr authored and fbricon committed Jul 10, 2019
1 parent 1e46c5d commit dabc1c4
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
33 changes: 33 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (c) 2019 Red Hat, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*/
'use strict';

/**
* Commonly used commands
*/
export namespace Commands {

/**
* Auto close tags
*/
export const AUTO_CLOSE_TAGS= 'xml.completion.autoCloseTags';

/**
* Show XML references
*/
export const SHOW_REFERENCES = 'xml.show.references';

/**
* Show editor references
*/
export const EDITOR_SHOW_REFERENCES = 'editor.action.showReferences';

}
33 changes: 29 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
*/

import { prepareExecutable } from './javaServerStarter';
import { LanguageClientOptions, RevealOutputChannelOn, LanguageClient, DidChangeConfigurationNotification, RequestType, TextDocumentPositionParams, RequestType0 } from 'vscode-languageclient';
import { LanguageClientOptions, RevealOutputChannelOn, LanguageClient, DidChangeConfigurationNotification, RequestType, TextDocumentPositionParams, ReferencesRequest } from 'vscode-languageclient';
import * as requirements from './requirements';
import { languages, IndentAction, workspace, window, commands, ExtensionContext, TextDocument, Position, LanguageConfiguration } from "vscode";
import { languages, IndentAction, workspace, window, commands, ExtensionContext, TextDocument, Position, LanguageConfiguration, Uri } from "vscode";
import * as path from 'path';
import * as os from 'os';
import { activateTagClosing, AutoCloseResult } from './tagClosing';
import { Commands } from './commands';

export interface ScopeInfo {
scope : "default" | "global" | "workspace" | "folder";
Expand Down Expand Up @@ -58,7 +59,18 @@ export function activate(context: ExtensionContext) {
],
revealOutputChannelOn: RevealOutputChannelOn.Never,
//wrap with key 'settings' so it can be handled same a DidChangeConfiguration
initializationOptions: {"settings": getXMLSettings()},
initializationOptions: {
settings: getXMLSettings(),
extendedClientCapabilities: {
codeLens: {
codeLensKind: {
valueSet: [
'references'
]
}
}
}
},
synchronize: {
//preferences starting with these will trigger didChangeConfiguration
configurationSection: ['xml', '[xml]']
Expand All @@ -83,14 +95,27 @@ export function activate(context: ExtensionContext) {
let disposable = languageClient.start();
toDispose.push(disposable);
languageClient.onReady().then(() => {

// Code Lens actions
context.subscriptions.push(commands.registerCommand(Commands.SHOW_REFERENCES, (uriString: string, position: Position) => {
const uri = Uri.parse(uriString);
workspace.openTextDocument(uri).then(document => {
// Consume references service from the XML Language Server
let param = languageClient.code2ProtocolConverter.asTextDocumentPositionParams(document, position);
languageClient.sendRequest(ReferencesRequest.type, param).then(locations => {
commands.executeCommand(Commands.EDITOR_SHOW_REFERENCES, uri, languageClient.protocol2CodeConverter.asPosition(position), locations.map(languageClient.protocol2CodeConverter.asLocation));
})
})
}));

//Setup autoCloseTags
let tagProvider = (document: TextDocument, position: Position) => {
let param = languageClient.code2ProtocolConverter.asTextDocumentPositionParams(document, position);
let text = languageClient.sendRequest(TagCloseRequest.type, param);
return text;
};

disposable = activateTagClosing(tagProvider, { xml: true, xsl: true }, 'xml.completion.autoCloseTags');
disposable = activateTagClosing(tagProvider, { xml: true, xsl: true }, Commands.AUTO_CLOSE_TAGS);
toDispose.push(disposable);
});
languages.setLanguageConfiguration('xml', getIndentationRules());
Expand Down

0 comments on commit dabc1c4

Please sign in to comment.