Support LiveShare
Implements the changes from #154. Co-Authored-By: Jonathan Carter <joncart@microsoft.com>
This commit is contained in:
parent
29756e3f97
commit
9e47281d91
8
src/common/create-document-selector.ts
Normal file
8
src/common/create-document-selector.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { DocumentFilter } from "vscode";
|
||||
|
||||
export function createDocumentSelector(language: string): DocumentFilter[] {
|
||||
return [
|
||||
{ language, scheme: "file" },
|
||||
{ language, scheme: "untitled" },
|
||||
];
|
||||
}
|
@ -30,6 +30,7 @@ export namespace diagnosticCollections {
|
||||
|
||||
export namespace languageIds {
|
||||
export const xml = "xml";
|
||||
export const xsd = "xsd";
|
||||
export const xquery = "xquery";
|
||||
}
|
||||
|
||||
@ -45,6 +46,11 @@ export namespace stateKeys {
|
||||
export const xPathQueryLast = "xPathQueryLast";
|
||||
}
|
||||
|
||||
export namespace uriSchemes {
|
||||
export const file = "file";
|
||||
export const untitled = "untitled";
|
||||
}
|
||||
|
||||
export namespace views {
|
||||
export const xmlTreeView = "xmlTreeView";
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { languages, window, workspace, commands } from "vscode";
|
||||
import { ExtensionContext, Memento, TextEditor, TextEditorSelectionChangeEvent, WorkspaceConfiguration } from "vscode";
|
||||
|
||||
import { createDocumentSelector } from "./common/create-document-selector";
|
||||
import { XQueryCompletionItemProvider } from "./completion/xquery-completion-item-provider";
|
||||
import { formatAsXml } from "./formatting/commands/formatAsXml";
|
||||
import { minifyXml } from "./formatting/commands/minifyXml";
|
||||
@ -21,9 +22,12 @@ export function activate(context: ExtensionContext) {
|
||||
|
||||
const config = workspace.getConfiguration(constants.extensionPrefix);
|
||||
|
||||
const xmlXsdDocSelector = [...createDocumentSelector(constants.languageIds.xml), ...createDocumentSelector(constants.languageIds.xsd)];
|
||||
const xqueryDocSelector = createDocumentSelector(constants.languageIds.xquery);
|
||||
|
||||
/* Completion Features */
|
||||
context.subscriptions.push(
|
||||
languages.registerCompletionItemProvider(constants.languageIds.xquery, new XQueryCompletionItemProvider(), ":", "$")
|
||||
languages.registerCompletionItemProvider(xqueryDocSelector, new XQueryCompletionItemProvider(), ":", "$")
|
||||
);
|
||||
|
||||
/* Formatting Features */
|
||||
@ -32,8 +36,8 @@ export function activate(context: ExtensionContext) {
|
||||
context.subscriptions.push(
|
||||
commands.registerTextEditorCommand(constants.commands.formatAsXml, formatAsXml),
|
||||
commands.registerTextEditorCommand(constants.commands.minifyXml, minifyXml),
|
||||
languages.registerDocumentFormattingEditProvider(constants.languageIds.xml, xmlFormattingEditProvider),
|
||||
languages.registerDocumentRangeFormattingEditProvider(constants.languageIds.xml, xmlFormattingEditProvider)
|
||||
languages.registerDocumentFormattingEditProvider(xmlXsdDocSelector, xmlFormattingEditProvider),
|
||||
languages.registerDocumentRangeFormattingEditProvider(xmlXsdDocSelector, xmlFormattingEditProvider)
|
||||
);
|
||||
|
||||
/* Linting Features */
|
||||
@ -64,7 +68,9 @@ export function deactivate() {
|
||||
|
||||
|
||||
function _handleContextChange(editor: TextEditor): void {
|
||||
if (!editor || !editor.document) {
|
||||
const supportedSchemes = [constants.uriSchemes.file, constants.uriSchemes.untitled];
|
||||
|
||||
if (!editor || !editor.document || supportedSchemes.indexOf(editor.document.uri.scheme) === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user