Version 1.0
This commit is contained in:
+8
@@ -0,0 +1,8 @@
|
||||
import { initialize } from '../../common/initialize.js';
|
||||
import { JSONWorker } from './jsonWorker.js';
|
||||
|
||||
self.onmessage = () => {
|
||||
initialize((ctx, createData) => {
|
||||
return new JSONWorker(ctx, createData);
|
||||
});
|
||||
};
|
||||
+224
@@ -0,0 +1,224 @@
|
||||
import { WorkerManager } from './workerManager.js';
|
||||
import { DocumentFormattingEditProvider, DocumentRangeFormattingEditProvider, CompletionAdapter, HoverAdapter, DocumentSymbolAdapter, DocumentColorAdapter, FoldingRangeAdapter, SelectionRangeAdapter, DiagnosticsAdapter } from '../common/lspLanguageFeatures.js';
|
||||
export { DefinitionAdapter, DocumentHighlightAdapter, DocumentLinkAdapter, ReferenceAdapter, RenameAdapter, fromPosition, fromRange, toRange, toTextEdit } from '../common/lspLanguageFeatures.js';
|
||||
import { createTokenizationSupport } from './tokenization.js';
|
||||
import '../../editor/browser/coreCommands.js';
|
||||
import '../../editor/browser/widget/codeEditor/codeEditorWidget.js';
|
||||
import '../../editor/browser/widget/diffEditor/diffEditor.contribution.js';
|
||||
import '../../editor/contrib/anchorSelect/browser/anchorSelect.js';
|
||||
import '../../editor/contrib/bracketMatching/browser/bracketMatching.js';
|
||||
import '../../editor/contrib/caretOperations/browser/caretOperations.js';
|
||||
import '../../editor/contrib/caretOperations/browser/transpose.js';
|
||||
import '../../editor/contrib/clipboard/browser/clipboard.js';
|
||||
import '../../editor/contrib/codeAction/browser/codeActionContributions.js';
|
||||
import '../../editor/contrib/codelens/browser/codelensController.js';
|
||||
import '../../editor/contrib/colorPicker/browser/colorPickerContribution.js';
|
||||
import '../../editor/contrib/comment/browser/comment.js';
|
||||
import '../../editor/contrib/contextmenu/browser/contextmenu.js';
|
||||
import '../../editor/contrib/cursorUndo/browser/cursorUndo.js';
|
||||
import '../../editor/contrib/dnd/browser/dnd.js';
|
||||
import '../../editor/contrib/dropOrPasteInto/browser/copyPasteContribution.js';
|
||||
import '../../editor/contrib/dropOrPasteInto/browser/dropIntoEditorContribution.js';
|
||||
import '../../editor/contrib/find/browser/findController.js';
|
||||
import '../../editor/contrib/folding/browser/folding.js';
|
||||
import '../../editor/contrib/fontZoom/browser/fontZoom.js';
|
||||
import '../../editor/contrib/format/browser/formatActions.js';
|
||||
import '../../editor/contrib/documentSymbols/browser/documentSymbols.js';
|
||||
import '../../editor/contrib/inlineCompletions/browser/inlineCompletions.contribution.js';
|
||||
import '../../editor/contrib/inlineProgress/browser/inlineProgress.js';
|
||||
import '../../editor/contrib/gotoSymbol/browser/goToCommands.js';
|
||||
import '../../editor/contrib/gotoSymbol/browser/link/goToDefinitionAtPosition.js';
|
||||
import '../../editor/contrib/gotoError/browser/gotoError.js';
|
||||
import '../../editor/contrib/gpu/browser/gpuActions.js';
|
||||
import '../../editor/contrib/hover/browser/hoverContribution.js';
|
||||
import '../../editor/contrib/indentation/browser/indentation.js';
|
||||
import '../../editor/contrib/inlayHints/browser/inlayHintsContribution.js';
|
||||
import '../../editor/contrib/inPlaceReplace/browser/inPlaceReplace.js';
|
||||
import '../../editor/contrib/insertFinalNewLine/browser/insertFinalNewLine.js';
|
||||
import '../../editor/contrib/lineSelection/browser/lineSelection.js';
|
||||
import '../../editor/contrib/linesOperations/browser/linesOperations.js';
|
||||
import '../../editor/contrib/linkedEditing/browser/linkedEditing.js';
|
||||
import '../../editor/contrib/links/browser/links.js';
|
||||
import '../../editor/contrib/longLinesHelper/browser/longLinesHelper.js';
|
||||
import '../../editor/contrib/middleScroll/browser/middleScroll.contribution.js';
|
||||
import '../../editor/contrib/multicursor/browser/multicursor.js';
|
||||
import '../../editor/contrib/parameterHints/browser/parameterHints.js';
|
||||
import '../../editor/contrib/placeholderText/browser/placeholderText.contribution.js';
|
||||
import '../../editor/contrib/rename/browser/rename.js';
|
||||
import '../../editor/contrib/sectionHeaders/browser/sectionHeaders.js';
|
||||
import '../../editor/contrib/semanticTokens/browser/documentSemanticTokens.js';
|
||||
import '../../editor/contrib/semanticTokens/browser/viewportSemanticTokens.js';
|
||||
import '../../editor/contrib/smartSelect/browser/smartSelect.js';
|
||||
import '../../editor/contrib/snippet/browser/snippetController2.js';
|
||||
import '../../editor/contrib/stickyScroll/browser/stickyScrollContribution.js';
|
||||
import '../../editor/contrib/suggest/browser/suggestController.js';
|
||||
import '../../editor/contrib/suggest/browser/suggestInlineCompletions.js';
|
||||
import '../../editor/contrib/tokenization/browser/tokenization.js';
|
||||
import '../../editor/contrib/toggleTabFocusMode/browser/toggleTabFocusMode.js';
|
||||
import '../../editor/contrib/unicodeHighlighter/browser/unicodeHighlighter.js';
|
||||
import '../../editor/contrib/unusualLineTerminators/browser/unusualLineTerminators.js';
|
||||
import '../../editor/contrib/wordHighlighter/browser/wordHighlighter.js';
|
||||
import '../../editor/contrib/wordOperations/browser/wordOperations.js';
|
||||
import '../../editor/contrib/wordPartOperations/browser/wordPartOperations.js';
|
||||
import '../../editor/contrib/readOnlyMessage/browser/contribution.js';
|
||||
import '../../editor/contrib/diffEditorBreadcrumbs/browser/contribution.js';
|
||||
import '../../editor/contrib/floatingMenu/browser/floatingMenu.contribution.js';
|
||||
import '../../editor/common/standaloneStrings.js';
|
||||
import '../../base/browser/ui/codicons/codicon/codicon.css';
|
||||
import '../../base/browser/ui/codicons/codicon/codicon-modifiers.css';
|
||||
import '../../editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.js';
|
||||
import '../../editor/standalone/browser/inspectTokens/inspectTokens.js';
|
||||
import '../../editor/standalone/browser/quickAccess/standaloneHelpQuickAccess.js';
|
||||
import '../../editor/standalone/browser/quickAccess/standaloneGotoLineQuickAccess.js';
|
||||
import '../../editor/standalone/browser/quickAccess/standaloneGotoSymbolQuickAccess.js';
|
||||
import '../../editor/standalone/browser/quickAccess/standaloneCommandsQuickAccess.js';
|
||||
import '../../editor/standalone/browser/referenceSearch/standaloneReferenceSearch.js';
|
||||
import '../../editor/standalone/browser/toggleHighContrast/toggleHighContrast.js';
|
||||
import { languages, editor } from '../../editor/editor.api2.js';
|
||||
|
||||
let worker;
|
||||
function getWorker() {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!worker) {
|
||||
return reject("JSON not registered!");
|
||||
}
|
||||
resolve(worker);
|
||||
});
|
||||
}
|
||||
class JSONDiagnosticsAdapter extends DiagnosticsAdapter {
|
||||
constructor(languageId, worker2, defaults) {
|
||||
super(languageId, worker2, defaults.onDidChange);
|
||||
this._disposables.push(
|
||||
editor.onWillDisposeModel((model) => {
|
||||
this._resetSchema(model.uri);
|
||||
})
|
||||
);
|
||||
this._disposables.push(
|
||||
editor.onDidChangeModelLanguage((event) => {
|
||||
this._resetSchema(event.model.uri);
|
||||
})
|
||||
);
|
||||
}
|
||||
_resetSchema(resource) {
|
||||
this._worker().then((worker2) => {
|
||||
worker2.resetSchema(resource.toString());
|
||||
});
|
||||
}
|
||||
}
|
||||
function setupMode(defaults) {
|
||||
const disposables = [];
|
||||
const providers = [];
|
||||
const client = new WorkerManager(defaults);
|
||||
disposables.push(client);
|
||||
worker = (...uris) => {
|
||||
return client.getLanguageServiceWorker(...uris);
|
||||
};
|
||||
function registerProviders() {
|
||||
const { languageId, modeConfiguration: modeConfiguration2 } = defaults;
|
||||
disposeAll(providers);
|
||||
if (modeConfiguration2.documentFormattingEdits) {
|
||||
providers.push(
|
||||
languages.registerDocumentFormattingEditProvider(
|
||||
languageId,
|
||||
new DocumentFormattingEditProvider(worker)
|
||||
)
|
||||
);
|
||||
}
|
||||
if (modeConfiguration2.documentRangeFormattingEdits) {
|
||||
providers.push(
|
||||
languages.registerDocumentRangeFormattingEditProvider(
|
||||
languageId,
|
||||
new DocumentRangeFormattingEditProvider(worker)
|
||||
)
|
||||
);
|
||||
}
|
||||
if (modeConfiguration2.completionItems) {
|
||||
providers.push(
|
||||
languages.registerCompletionItemProvider(
|
||||
languageId,
|
||||
new CompletionAdapter(worker, [" ", ":", '"'])
|
||||
)
|
||||
);
|
||||
}
|
||||
if (modeConfiguration2.hovers) {
|
||||
providers.push(
|
||||
languages.registerHoverProvider(languageId, new HoverAdapter(worker))
|
||||
);
|
||||
}
|
||||
if (modeConfiguration2.documentSymbols) {
|
||||
providers.push(
|
||||
languages.registerDocumentSymbolProvider(
|
||||
languageId,
|
||||
new DocumentSymbolAdapter(worker)
|
||||
)
|
||||
);
|
||||
}
|
||||
if (modeConfiguration2.tokens) {
|
||||
providers.push(languages.setTokensProvider(languageId, createTokenizationSupport(true)));
|
||||
}
|
||||
if (modeConfiguration2.colors) {
|
||||
providers.push(
|
||||
languages.registerColorProvider(
|
||||
languageId,
|
||||
new DocumentColorAdapter(worker)
|
||||
)
|
||||
);
|
||||
}
|
||||
if (modeConfiguration2.foldingRanges) {
|
||||
providers.push(
|
||||
languages.registerFoldingRangeProvider(
|
||||
languageId,
|
||||
new FoldingRangeAdapter(worker)
|
||||
)
|
||||
);
|
||||
}
|
||||
if (modeConfiguration2.diagnostics) {
|
||||
providers.push(new JSONDiagnosticsAdapter(languageId, worker, defaults));
|
||||
}
|
||||
if (modeConfiguration2.selectionRanges) {
|
||||
providers.push(
|
||||
languages.registerSelectionRangeProvider(
|
||||
languageId,
|
||||
new SelectionRangeAdapter(worker)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
registerProviders();
|
||||
disposables.push(languages.setLanguageConfiguration(defaults.languageId, richEditConfiguration));
|
||||
let modeConfiguration = defaults.modeConfiguration;
|
||||
defaults.onDidChange((newDefaults) => {
|
||||
if (newDefaults.modeConfiguration !== modeConfiguration) {
|
||||
modeConfiguration = newDefaults.modeConfiguration;
|
||||
registerProviders();
|
||||
}
|
||||
});
|
||||
disposables.push(asDisposable(providers));
|
||||
return asDisposable(disposables);
|
||||
}
|
||||
function asDisposable(disposables) {
|
||||
return { dispose: () => disposeAll(disposables) };
|
||||
}
|
||||
function disposeAll(disposables) {
|
||||
while (disposables.length) {
|
||||
disposables.pop().dispose();
|
||||
}
|
||||
}
|
||||
const richEditConfiguration = {
|
||||
wordPattern: /(-?\d*\.\d\w*)|([^\[\{\]\}\:\"\,\s]+)/g,
|
||||
comments: {
|
||||
lineComment: "//",
|
||||
blockComment: ["/*", "*/"]
|
||||
},
|
||||
brackets: [
|
||||
["{", "}"],
|
||||
["[", "]"]
|
||||
],
|
||||
autoClosingPairs: [
|
||||
{ open: "{", close: "}", notIn: ["string"] },
|
||||
{ open: "[", close: "]", notIn: ["string"] },
|
||||
{ open: '"', close: '"', notIn: ["string"] }
|
||||
]
|
||||
};
|
||||
|
||||
export { CompletionAdapter, DiagnosticsAdapter, DocumentColorAdapter, DocumentFormattingEditProvider, DocumentRangeFormattingEditProvider, DocumentSymbolAdapter, FoldingRangeAdapter, HoverAdapter, SelectionRangeAdapter, WorkerManager, getWorker, setupMode };
|
||||
+187
@@ -0,0 +1,187 @@
|
||||
import { getLanguageService } from '../../../external/vscode-json-languageservice/lib/esm/jsonLanguageService.js';
|
||||
import { URI } from '../../../external/vscode-uri/lib/esm/index.js';
|
||||
import { ClientCapabilities } from '../../../external/vscode-json-languageservice/lib/esm/jsonLanguageTypes.js';
|
||||
import { TextDocument } from '../../../external/vscode-languageserver-textdocument/lib/esm/main.js';
|
||||
|
||||
let defaultSchemaRequestService;
|
||||
if (typeof fetch !== "undefined") {
|
||||
defaultSchemaRequestService = function(url) {
|
||||
return fetch(url).then((response) => response.text());
|
||||
};
|
||||
}
|
||||
class JSONWorker {
|
||||
constructor(ctx, createData) {
|
||||
this._ctx = ctx;
|
||||
this._languageSettings = createData.languageSettings;
|
||||
this._languageId = createData.languageId;
|
||||
this._languageService = getLanguageService({
|
||||
workspaceContext: {
|
||||
resolveRelativePath: (relativePath, resource) => {
|
||||
const base = resource.substr(0, resource.lastIndexOf("/") + 1);
|
||||
return resolvePath(base, relativePath);
|
||||
}
|
||||
},
|
||||
schemaRequestService: createData.enableSchemaRequest ? defaultSchemaRequestService : void 0,
|
||||
clientCapabilities: ClientCapabilities.LATEST
|
||||
});
|
||||
this._languageService.configure(this._languageSettings);
|
||||
}
|
||||
async doValidation(uri) {
|
||||
let document = this._getTextDocument(uri);
|
||||
if (document) {
|
||||
let jsonDocument = this._languageService.parseJSONDocument(document);
|
||||
return this._languageService.doValidation(document, jsonDocument, this._languageSettings);
|
||||
}
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
async doComplete(uri, position) {
|
||||
let document = this._getTextDocument(uri);
|
||||
if (!document) {
|
||||
return null;
|
||||
}
|
||||
let jsonDocument = this._languageService.parseJSONDocument(document);
|
||||
return this._languageService.doComplete(document, position, jsonDocument);
|
||||
}
|
||||
async doResolve(item) {
|
||||
return this._languageService.doResolve(item);
|
||||
}
|
||||
async doHover(uri, position) {
|
||||
let document = this._getTextDocument(uri);
|
||||
if (!document) {
|
||||
return null;
|
||||
}
|
||||
let jsonDocument = this._languageService.parseJSONDocument(document);
|
||||
return this._languageService.doHover(document, position, jsonDocument);
|
||||
}
|
||||
async format(uri, range, options) {
|
||||
let document = this._getTextDocument(uri);
|
||||
if (!document) {
|
||||
return [];
|
||||
}
|
||||
let textEdits = this._languageService.format(document, range, options);
|
||||
return Promise.resolve(textEdits);
|
||||
}
|
||||
async resetSchema(uri) {
|
||||
return Promise.resolve(this._languageService.resetSchema(uri));
|
||||
}
|
||||
async findDocumentSymbols(uri) {
|
||||
let document = this._getTextDocument(uri);
|
||||
if (!document) {
|
||||
return [];
|
||||
}
|
||||
let jsonDocument = this._languageService.parseJSONDocument(document);
|
||||
let symbols = this._languageService.findDocumentSymbols2(document, jsonDocument);
|
||||
return Promise.resolve(symbols);
|
||||
}
|
||||
async findDocumentColors(uri) {
|
||||
let document = this._getTextDocument(uri);
|
||||
if (!document) {
|
||||
return [];
|
||||
}
|
||||
let jsonDocument = this._languageService.parseJSONDocument(document);
|
||||
let colorSymbols = this._languageService.findDocumentColors(document, jsonDocument);
|
||||
return Promise.resolve(colorSymbols);
|
||||
}
|
||||
async getColorPresentations(uri, color, range) {
|
||||
let document = this._getTextDocument(uri);
|
||||
if (!document) {
|
||||
return [];
|
||||
}
|
||||
let jsonDocument = this._languageService.parseJSONDocument(document);
|
||||
let colorPresentations = this._languageService.getColorPresentations(
|
||||
document,
|
||||
jsonDocument,
|
||||
color,
|
||||
range
|
||||
);
|
||||
return Promise.resolve(colorPresentations);
|
||||
}
|
||||
async getFoldingRanges(uri, context) {
|
||||
let document = this._getTextDocument(uri);
|
||||
if (!document) {
|
||||
return [];
|
||||
}
|
||||
let ranges = this._languageService.getFoldingRanges(document, context);
|
||||
return Promise.resolve(ranges);
|
||||
}
|
||||
async getSelectionRanges(uri, positions) {
|
||||
let document = this._getTextDocument(uri);
|
||||
if (!document) {
|
||||
return [];
|
||||
}
|
||||
let jsonDocument = this._languageService.parseJSONDocument(document);
|
||||
let ranges = this._languageService.getSelectionRanges(document, positions, jsonDocument);
|
||||
return Promise.resolve(ranges);
|
||||
}
|
||||
async parseJSONDocument(uri) {
|
||||
let document = this._getTextDocument(uri);
|
||||
if (!document) {
|
||||
return null;
|
||||
}
|
||||
let jsonDocument = this._languageService.parseJSONDocument(document);
|
||||
return Promise.resolve(jsonDocument);
|
||||
}
|
||||
async getMatchingSchemas(uri) {
|
||||
let document = this._getTextDocument(uri);
|
||||
if (!document) {
|
||||
return [];
|
||||
}
|
||||
let jsonDocument = this._languageService.parseJSONDocument(document);
|
||||
return Promise.resolve(this._languageService.getMatchingSchemas(document, jsonDocument));
|
||||
}
|
||||
_getTextDocument(uri) {
|
||||
let models = this._ctx.getMirrorModels();
|
||||
for (let model of models) {
|
||||
if (model.uri.toString() === uri) {
|
||||
return TextDocument.create(
|
||||
uri,
|
||||
this._languageId,
|
||||
model.version,
|
||||
model.getValue()
|
||||
);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
const Slash = "/".charCodeAt(0);
|
||||
const Dot = ".".charCodeAt(0);
|
||||
function isAbsolutePath(path) {
|
||||
return path.charCodeAt(0) === Slash;
|
||||
}
|
||||
function resolvePath(uriString, path) {
|
||||
if (isAbsolutePath(path)) {
|
||||
const uri = URI.parse(uriString);
|
||||
const parts = path.split("/");
|
||||
return uri.with({ path: normalizePath(parts) }).toString();
|
||||
}
|
||||
return joinPath(uriString, path);
|
||||
}
|
||||
function normalizePath(parts) {
|
||||
const newParts = [];
|
||||
for (const part of parts) {
|
||||
if (part.length === 0 || part.length === 1 && part.charCodeAt(0) === Dot) ; else if (part.length === 2 && part.charCodeAt(0) === Dot && part.charCodeAt(1) === Dot) {
|
||||
newParts.pop();
|
||||
} else {
|
||||
newParts.push(part);
|
||||
}
|
||||
}
|
||||
if (parts.length > 1 && parts[parts.length - 1].length === 0) {
|
||||
newParts.push("");
|
||||
}
|
||||
let res = newParts.join("/");
|
||||
if (parts[0].length === 0) {
|
||||
res = "/" + res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
function joinPath(uriString, ...paths) {
|
||||
const uri = URI.parse(uriString);
|
||||
const parts = uri.path.split("/");
|
||||
for (let path of paths) {
|
||||
parts.push(...path.split("/"));
|
||||
}
|
||||
return uri.with({ path: normalizePath(parts) }).toString();
|
||||
}
|
||||
|
||||
export { JSONWorker };
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export {}
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
import '../../editor/browser/coreCommands.js';
|
||||
import '../../editor/browser/widget/codeEditor/codeEditorWidget.js';
|
||||
import '../../editor/browser/widget/diffEditor/diffEditor.contribution.js';
|
||||
import '../../editor/contrib/anchorSelect/browser/anchorSelect.js';
|
||||
import '../../editor/contrib/bracketMatching/browser/bracketMatching.js';
|
||||
import '../../editor/contrib/caretOperations/browser/caretOperations.js';
|
||||
import '../../editor/contrib/caretOperations/browser/transpose.js';
|
||||
import '../../editor/contrib/clipboard/browser/clipboard.js';
|
||||
import '../../editor/contrib/codeAction/browser/codeActionContributions.js';
|
||||
import '../../editor/contrib/codelens/browser/codelensController.js';
|
||||
import '../../editor/contrib/colorPicker/browser/colorPickerContribution.js';
|
||||
import '../../editor/contrib/comment/browser/comment.js';
|
||||
import '../../editor/contrib/contextmenu/browser/contextmenu.js';
|
||||
import '../../editor/contrib/cursorUndo/browser/cursorUndo.js';
|
||||
import '../../editor/contrib/dnd/browser/dnd.js';
|
||||
import '../../editor/contrib/dropOrPasteInto/browser/copyPasteContribution.js';
|
||||
import '../../editor/contrib/dropOrPasteInto/browser/dropIntoEditorContribution.js';
|
||||
import '../../editor/contrib/find/browser/findController.js';
|
||||
import '../../editor/contrib/folding/browser/folding.js';
|
||||
import '../../editor/contrib/fontZoom/browser/fontZoom.js';
|
||||
import '../../editor/contrib/format/browser/formatActions.js';
|
||||
import '../../editor/contrib/documentSymbols/browser/documentSymbols.js';
|
||||
import '../../editor/contrib/inlineCompletions/browser/inlineCompletions.contribution.js';
|
||||
import '../../editor/contrib/inlineProgress/browser/inlineProgress.js';
|
||||
import '../../editor/contrib/gotoSymbol/browser/goToCommands.js';
|
||||
import '../../editor/contrib/gotoSymbol/browser/link/goToDefinitionAtPosition.js';
|
||||
import '../../editor/contrib/gotoError/browser/gotoError.js';
|
||||
import '../../editor/contrib/gpu/browser/gpuActions.js';
|
||||
import '../../editor/contrib/hover/browser/hoverContribution.js';
|
||||
import '../../editor/contrib/indentation/browser/indentation.js';
|
||||
import '../../editor/contrib/inlayHints/browser/inlayHintsContribution.js';
|
||||
import '../../editor/contrib/inPlaceReplace/browser/inPlaceReplace.js';
|
||||
import '../../editor/contrib/insertFinalNewLine/browser/insertFinalNewLine.js';
|
||||
import '../../editor/contrib/lineSelection/browser/lineSelection.js';
|
||||
import '../../editor/contrib/linesOperations/browser/linesOperations.js';
|
||||
import '../../editor/contrib/linkedEditing/browser/linkedEditing.js';
|
||||
import '../../editor/contrib/links/browser/links.js';
|
||||
import '../../editor/contrib/longLinesHelper/browser/longLinesHelper.js';
|
||||
import '../../editor/contrib/middleScroll/browser/middleScroll.contribution.js';
|
||||
import '../../editor/contrib/multicursor/browser/multicursor.js';
|
||||
import '../../editor/contrib/parameterHints/browser/parameterHints.js';
|
||||
import '../../editor/contrib/placeholderText/browser/placeholderText.contribution.js';
|
||||
import '../../editor/contrib/rename/browser/rename.js';
|
||||
import '../../editor/contrib/sectionHeaders/browser/sectionHeaders.js';
|
||||
import '../../editor/contrib/semanticTokens/browser/documentSemanticTokens.js';
|
||||
import '../../editor/contrib/semanticTokens/browser/viewportSemanticTokens.js';
|
||||
import '../../editor/contrib/smartSelect/browser/smartSelect.js';
|
||||
import '../../editor/contrib/snippet/browser/snippetController2.js';
|
||||
import '../../editor/contrib/stickyScroll/browser/stickyScrollContribution.js';
|
||||
import '../../editor/contrib/suggest/browser/suggestController.js';
|
||||
import '../../editor/contrib/suggest/browser/suggestInlineCompletions.js';
|
||||
import '../../editor/contrib/tokenization/browser/tokenization.js';
|
||||
import '../../editor/contrib/toggleTabFocusMode/browser/toggleTabFocusMode.js';
|
||||
import '../../editor/contrib/unicodeHighlighter/browser/unicodeHighlighter.js';
|
||||
import '../../editor/contrib/unusualLineTerminators/browser/unusualLineTerminators.js';
|
||||
import '../../editor/contrib/wordHighlighter/browser/wordHighlighter.js';
|
||||
import '../../editor/contrib/wordOperations/browser/wordOperations.js';
|
||||
import '../../editor/contrib/wordPartOperations/browser/wordPartOperations.js';
|
||||
import '../../editor/contrib/readOnlyMessage/browser/contribution.js';
|
||||
import '../../editor/contrib/diffEditorBreadcrumbs/browser/contribution.js';
|
||||
import '../../editor/contrib/floatingMenu/browser/floatingMenu.contribution.js';
|
||||
import '../../editor/common/standaloneStrings.js';
|
||||
import '../../base/browser/ui/codicons/codicon/codicon.css';
|
||||
import '../../base/browser/ui/codicons/codicon/codicon-modifiers.css';
|
||||
import '../../editor/standalone/browser/iPadShowKeyboard/iPadShowKeyboard.js';
|
||||
import '../../editor/standalone/browser/inspectTokens/inspectTokens.js';
|
||||
import '../../editor/standalone/browser/quickAccess/standaloneHelpQuickAccess.js';
|
||||
import '../../editor/standalone/browser/quickAccess/standaloneGotoLineQuickAccess.js';
|
||||
import '../../editor/standalone/browser/quickAccess/standaloneGotoSymbolQuickAccess.js';
|
||||
import '../../editor/standalone/browser/quickAccess/standaloneCommandsQuickAccess.js';
|
||||
import '../../editor/standalone/browser/referenceSearch/standaloneReferenceSearch.js';
|
||||
import '../../editor/standalone/browser/toggleHighContrast/toggleHighContrast.js';
|
||||
import { languages, Emitter } from '../../editor/editor.api2.js';
|
||||
|
||||
class LanguageServiceDefaultsImpl {
|
||||
constructor(languageId, diagnosticsOptions, modeConfiguration) {
|
||||
this._onDidChange = new Emitter();
|
||||
this._languageId = languageId;
|
||||
this.setDiagnosticsOptions(diagnosticsOptions);
|
||||
this.setModeConfiguration(modeConfiguration);
|
||||
}
|
||||
get onDidChange() {
|
||||
return this._onDidChange.event;
|
||||
}
|
||||
get languageId() {
|
||||
return this._languageId;
|
||||
}
|
||||
get modeConfiguration() {
|
||||
return this._modeConfiguration;
|
||||
}
|
||||
get diagnosticsOptions() {
|
||||
return this._diagnosticsOptions;
|
||||
}
|
||||
setDiagnosticsOptions(options) {
|
||||
this._diagnosticsOptions = options || /* @__PURE__ */ Object.create(null);
|
||||
this._onDidChange.fire(this);
|
||||
}
|
||||
setModeConfiguration(modeConfiguration) {
|
||||
this._modeConfiguration = modeConfiguration || /* @__PURE__ */ Object.create(null);
|
||||
this._onDidChange.fire(this);
|
||||
}
|
||||
}
|
||||
const diagnosticDefault = {
|
||||
validate: true,
|
||||
allowComments: true,
|
||||
schemas: [],
|
||||
enableSchemaRequest: false,
|
||||
schemaRequest: "warning",
|
||||
schemaValidation: "warning",
|
||||
comments: "error",
|
||||
trailingCommas: "error"
|
||||
};
|
||||
const modeConfigurationDefault = {
|
||||
documentFormattingEdits: true,
|
||||
documentRangeFormattingEdits: true,
|
||||
completionItems: true,
|
||||
hovers: true,
|
||||
documentSymbols: true,
|
||||
tokens: true,
|
||||
colors: true,
|
||||
foldingRanges: true,
|
||||
diagnostics: true,
|
||||
selectionRanges: true
|
||||
};
|
||||
const jsonDefaults = new LanguageServiceDefaultsImpl(
|
||||
"json",
|
||||
diagnosticDefault,
|
||||
modeConfigurationDefault
|
||||
);
|
||||
const getWorker = () => getMode().then((mode2) => mode2.getWorker());
|
||||
function getMode() {
|
||||
return import('./jsonMode.js');
|
||||
}
|
||||
languages.register({
|
||||
id: "json",
|
||||
extensions: [".json", ".bowerrc", ".jshintrc", ".jscsrc", ".eslintrc", ".babelrc", ".har"],
|
||||
aliases: ["JSON", "json"],
|
||||
mimetypes: ["application/json"]
|
||||
});
|
||||
languages.onLanguage("json", () => {
|
||||
getMode().then((mode2) => mode2.setupMode(jsonDefaults));
|
||||
});
|
||||
|
||||
export { getWorker, jsonDefaults };
|
||||
+189
@@ -0,0 +1,189 @@
|
||||
import { createScanner } from '../../../external/jsonc-parser/lib/esm/main.js';
|
||||
|
||||
function createTokenizationSupport(supportComments) {
|
||||
return {
|
||||
getInitialState: () => new JSONState(null, null, false, null),
|
||||
tokenize: (line, state) => tokenize(supportComments, line, state)
|
||||
};
|
||||
}
|
||||
const TOKEN_DELIM_OBJECT = "delimiter.bracket.json";
|
||||
const TOKEN_DELIM_ARRAY = "delimiter.array.json";
|
||||
const TOKEN_DELIM_COLON = "delimiter.colon.json";
|
||||
const TOKEN_DELIM_COMMA = "delimiter.comma.json";
|
||||
const TOKEN_VALUE_BOOLEAN = "keyword.json";
|
||||
const TOKEN_VALUE_NULL = "keyword.json";
|
||||
const TOKEN_VALUE_STRING = "string.value.json";
|
||||
const TOKEN_VALUE_NUMBER = "number.json";
|
||||
const TOKEN_PROPERTY_NAME = "string.key.json";
|
||||
const TOKEN_COMMENT_BLOCK = "comment.block.json";
|
||||
const TOKEN_COMMENT_LINE = "comment.line.json";
|
||||
class ParentsStack {
|
||||
constructor(parent, type) {
|
||||
this.parent = parent;
|
||||
this.type = type;
|
||||
}
|
||||
static pop(parents) {
|
||||
if (parents) {
|
||||
return parents.parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
static push(parents, type) {
|
||||
return new ParentsStack(parents, type);
|
||||
}
|
||||
static equals(a, b) {
|
||||
if (!a && !b) {
|
||||
return true;
|
||||
}
|
||||
if (!a || !b) {
|
||||
return false;
|
||||
}
|
||||
while (a && b) {
|
||||
if (a === b) {
|
||||
return true;
|
||||
}
|
||||
if (a.type !== b.type) {
|
||||
return false;
|
||||
}
|
||||
a = a.parent;
|
||||
b = b.parent;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
class JSONState {
|
||||
constructor(state, scanError, lastWasColon, parents) {
|
||||
this._state = state;
|
||||
this.scanError = scanError;
|
||||
this.lastWasColon = lastWasColon;
|
||||
this.parents = parents;
|
||||
}
|
||||
clone() {
|
||||
return new JSONState(this._state, this.scanError, this.lastWasColon, this.parents);
|
||||
}
|
||||
equals(other) {
|
||||
if (other === this) {
|
||||
return true;
|
||||
}
|
||||
if (!other || !(other instanceof JSONState)) {
|
||||
return false;
|
||||
}
|
||||
return this.scanError === other.scanError && this.lastWasColon === other.lastWasColon && ParentsStack.equals(this.parents, other.parents);
|
||||
}
|
||||
getStateData() {
|
||||
return this._state;
|
||||
}
|
||||
setStateData(state) {
|
||||
this._state = state;
|
||||
}
|
||||
}
|
||||
function tokenize(comments, line, state, offsetDelta = 0) {
|
||||
let numberOfInsertedCharacters = 0;
|
||||
let adjustOffset = false;
|
||||
switch (state.scanError) {
|
||||
case 2 /* UnexpectedEndOfString */:
|
||||
line = '"' + line;
|
||||
numberOfInsertedCharacters = 1;
|
||||
break;
|
||||
case 1 /* UnexpectedEndOfComment */:
|
||||
line = "/*" + line;
|
||||
numberOfInsertedCharacters = 2;
|
||||
break;
|
||||
}
|
||||
const scanner = createScanner(line);
|
||||
let lastWasColon = state.lastWasColon;
|
||||
let parents = state.parents;
|
||||
const ret = {
|
||||
tokens: [],
|
||||
endState: state.clone()
|
||||
};
|
||||
while (true) {
|
||||
let offset = offsetDelta + scanner.getPosition();
|
||||
let type = "";
|
||||
const kind = scanner.scan();
|
||||
if (kind === 17 /* EOF */) {
|
||||
break;
|
||||
}
|
||||
if (offset === offsetDelta + scanner.getPosition()) {
|
||||
throw new Error(
|
||||
"Scanner did not advance, next 3 characters are: " + line.substr(scanner.getPosition(), 3)
|
||||
);
|
||||
}
|
||||
if (adjustOffset) {
|
||||
offset -= numberOfInsertedCharacters;
|
||||
}
|
||||
adjustOffset = numberOfInsertedCharacters > 0;
|
||||
switch (kind) {
|
||||
case 1 /* OpenBraceToken */:
|
||||
parents = ParentsStack.push(parents, 0 /* Object */);
|
||||
type = TOKEN_DELIM_OBJECT;
|
||||
lastWasColon = false;
|
||||
break;
|
||||
case 2 /* CloseBraceToken */:
|
||||
parents = ParentsStack.pop(parents);
|
||||
type = TOKEN_DELIM_OBJECT;
|
||||
lastWasColon = false;
|
||||
break;
|
||||
case 3 /* OpenBracketToken */:
|
||||
parents = ParentsStack.push(parents, 1 /* Array */);
|
||||
type = TOKEN_DELIM_ARRAY;
|
||||
lastWasColon = false;
|
||||
break;
|
||||
case 4 /* CloseBracketToken */:
|
||||
parents = ParentsStack.pop(parents);
|
||||
type = TOKEN_DELIM_ARRAY;
|
||||
lastWasColon = false;
|
||||
break;
|
||||
case 6 /* ColonToken */:
|
||||
type = TOKEN_DELIM_COLON;
|
||||
lastWasColon = true;
|
||||
break;
|
||||
case 5 /* CommaToken */:
|
||||
type = TOKEN_DELIM_COMMA;
|
||||
lastWasColon = false;
|
||||
break;
|
||||
case 8 /* TrueKeyword */:
|
||||
case 9 /* FalseKeyword */:
|
||||
type = TOKEN_VALUE_BOOLEAN;
|
||||
lastWasColon = false;
|
||||
break;
|
||||
case 7 /* NullKeyword */:
|
||||
type = TOKEN_VALUE_NULL;
|
||||
lastWasColon = false;
|
||||
break;
|
||||
case 10 /* StringLiteral */:
|
||||
const currentParent = parents ? parents.type : 0 /* Object */;
|
||||
const inArray = currentParent === 1 /* Array */;
|
||||
type = lastWasColon || inArray ? TOKEN_VALUE_STRING : TOKEN_PROPERTY_NAME;
|
||||
lastWasColon = false;
|
||||
break;
|
||||
case 11 /* NumericLiteral */:
|
||||
type = TOKEN_VALUE_NUMBER;
|
||||
lastWasColon = false;
|
||||
break;
|
||||
}
|
||||
{
|
||||
switch (kind) {
|
||||
case 12 /* LineCommentTrivia */:
|
||||
type = TOKEN_COMMENT_LINE;
|
||||
break;
|
||||
case 13 /* BlockCommentTrivia */:
|
||||
type = TOKEN_COMMENT_BLOCK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ret.endState = new JSONState(
|
||||
state.getStateData(),
|
||||
scanner.getTokenError(),
|
||||
lastWasColon,
|
||||
parents
|
||||
);
|
||||
ret.tokens.push({
|
||||
startIndex: offset,
|
||||
scopes: type
|
||||
});
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
export { TOKEN_COMMENT_BLOCK, TOKEN_COMMENT_LINE, TOKEN_DELIM_ARRAY, TOKEN_DELIM_COLON, TOKEN_DELIM_COMMA, TOKEN_DELIM_OBJECT, TOKEN_PROPERTY_NAME, TOKEN_VALUE_BOOLEAN, TOKEN_VALUE_NULL, TOKEN_VALUE_NUMBER, TOKEN_VALUE_STRING, createTokenizationSupport };
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
import { createWebWorker } from '../../common/workers.js';
|
||||
|
||||
const STOP_WHEN_IDLE_FOR = 2 * 60 * 1e3;
|
||||
class WorkerManager {
|
||||
constructor(defaults) {
|
||||
this._defaults = defaults;
|
||||
this._worker = null;
|
||||
this._client = null;
|
||||
this._idleCheckInterval = window.setInterval(() => this._checkIfIdle(), 30 * 1e3);
|
||||
this._lastUsedTime = 0;
|
||||
this._configChangeListener = this._defaults.onDidChange(() => this._stopWorker());
|
||||
}
|
||||
_stopWorker() {
|
||||
if (this._worker) {
|
||||
this._worker.dispose();
|
||||
this._worker = null;
|
||||
}
|
||||
this._client = null;
|
||||
}
|
||||
dispose() {
|
||||
clearInterval(this._idleCheckInterval);
|
||||
this._configChangeListener.dispose();
|
||||
this._stopWorker();
|
||||
}
|
||||
_checkIfIdle() {
|
||||
if (!this._worker) {
|
||||
return;
|
||||
}
|
||||
let timePassedSinceLastUsed = Date.now() - this._lastUsedTime;
|
||||
if (timePassedSinceLastUsed > STOP_WHEN_IDLE_FOR) {
|
||||
this._stopWorker();
|
||||
}
|
||||
}
|
||||
_getClient() {
|
||||
this._lastUsedTime = Date.now();
|
||||
if (!this._client) {
|
||||
this._worker = createWebWorker({
|
||||
// module that exports the create() method and returns a `JSONWorker` instance
|
||||
moduleId: "vs/language/json/jsonWorker",
|
||||
createWorker: () => new Worker(new URL('json.worker.js', import.meta.url), { type: "module" }),
|
||||
label: this._defaults.languageId,
|
||||
// passed in to the create() method
|
||||
createData: {
|
||||
languageSettings: this._defaults.diagnosticsOptions,
|
||||
languageId: this._defaults.languageId,
|
||||
enableSchemaRequest: this._defaults.diagnosticsOptions.enableSchemaRequest
|
||||
}
|
||||
});
|
||||
this._client = this._worker.getProxy();
|
||||
}
|
||||
return this._client;
|
||||
}
|
||||
getLanguageServiceWorker(...resources) {
|
||||
let _client;
|
||||
return this._getClient().then((client) => {
|
||||
_client = client;
|
||||
}).then((_) => {
|
||||
if (this._worker) {
|
||||
return this._worker.withSyncedResources(resources);
|
||||
}
|
||||
}).then((_) => _client);
|
||||
}
|
||||
}
|
||||
|
||||
export { WorkerManager };
|
||||
Reference in New Issue
Block a user