forked from redhat-developer/vscode-xml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Contribute to vscode-xml with a custom language
Fixes redhat-developer#589 Signed-off-by: azerr <azerr@redhat.com>
- Loading branch information
1 parent
8270daa
commit d6371e3
Showing
4 changed files
with
144 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"title": "XML Language server contributions to package.json", | ||
"type": "object", | ||
"properties": { | ||
"contributes": { | ||
"type": "object", | ||
"properties": { | ||
"xml.javaExtensions": { | ||
"type": "array", | ||
"markdownDescription": "XML language server extensions", | ||
"items": { | ||
"type": "string", | ||
"description": "Relative path to a XML language server extension JAR file" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"title": "XML Language server contributions to package.json", | ||
"type": "object", | ||
"properties": { | ||
"contributes": { | ||
"type": "object", | ||
"properties": { | ||
"xml.javaExtensions": { | ||
"type": "array", | ||
"markdownDescription": "XML language server extensions", | ||
"items": { | ||
"type": "string", | ||
"description": "Relative path to a XML language server extension JAR file" | ||
} | ||
}, | ||
"xmlLanguageParticipants": { | ||
"type": "array", | ||
"description": "A list of languages that participate with the XML language server.", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"languageId": { | ||
"type": "string", | ||
"description": "The id of the language that participates with XML language server." | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { DocumentSelector } from 'vscode-languageclient'; | ||
import { Event, EventEmitter, extensions } from 'vscode'; | ||
|
||
/** | ||
* XML language participant contribution. | ||
*/ | ||
interface LanguageParticipantContribution { | ||
/** | ||
* The id of the language which participates with the XML language server. | ||
*/ | ||
languageId: string; | ||
} | ||
|
||
export interface LanguageParticipants { | ||
readonly onDidChange: Event<void>; | ||
readonly documentSelector: DocumentSelector; | ||
hasLanguage(languageId: string): boolean; | ||
dispose(): void; | ||
} | ||
|
||
export function getLanguageParticipants(): LanguageParticipants { | ||
const onDidChangeEmmiter = new EventEmitter<void>(); | ||
let languages = new Set<string>(); | ||
|
||
function update() { | ||
const oldLanguages = languages; | ||
|
||
languages = new Set(); | ||
languages.add('xml'); | ||
languages.add('xsl'); | ||
languages.add('dtd'); | ||
languages.add('svg'); | ||
|
||
for (const extension of extensions.all /*extensions.allAcrossExtensionHosts*/) { | ||
const xmlLanguageParticipants = extension.packageJSON?.contributes?.xmlLanguageParticipants as LanguageParticipantContribution[]; | ||
if (Array.isArray(xmlLanguageParticipants)) { | ||
for (const xmlLanguageParticipant of xmlLanguageParticipants) { | ||
const languageId = xmlLanguageParticipant.languageId; | ||
if (typeof languageId === 'string') { | ||
languages.add(languageId); | ||
} | ||
} | ||
} | ||
} | ||
return !isEqualSet(languages, oldLanguages); | ||
} | ||
update(); | ||
|
||
const changeListener = extensions.onDidChange(_ => { | ||
if (update()) { | ||
onDidChangeEmmiter.fire(); | ||
} | ||
}); | ||
|
||
return { | ||
onDidChange: onDidChangeEmmiter.event, | ||
get documentSelector() { return Array.from(languages); }, | ||
hasLanguage(languageId: string) { return languages.has(languageId); }, | ||
dispose: () => changeListener.dispose() | ||
}; | ||
} | ||
|
||
function isEqualSet<T>(s1: Set<T>, s2: Set<T>) { | ||
if (s1.size !== s2.size) { | ||
return false; | ||
} | ||
for (const e of s1) { | ||
if (!s2.has(e)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters