diff --git a/.prettierrc b/.prettierrc index e1b5c6fc..c12f08c5 100644 --- a/.prettierrc +++ b/.prettierrc @@ -3,5 +3,6 @@ "singleQuote": true, "trailingComma": "none", "semi": true, - "useTabs": true + "useTabs": true, + "printWidth": 100 } diff --git a/scripts/bundle.js b/scripts/bundle.js index e53c42c2..e2883148 100644 --- a/scripts/bundle.js +++ b/scripts/bundle.js @@ -40,26 +40,17 @@ function bundleOne(moduleId, exclude) { packages: [ { name: 'vscode-json-languageservice', - location: path.join( - REPO_ROOT, - 'node_modules/vscode-json-languageservice/lib/umd' - ), + location: path.join(REPO_ROOT, 'node_modules/vscode-json-languageservice/lib/umd'), main: 'jsonLanguageService' }, { name: 'vscode-languageserver-types', - location: path.join( - REPO_ROOT, - 'node_modules/vscode-languageserver-types/lib/umd' - ), + location: path.join(REPO_ROOT, 'node_modules/vscode-languageserver-types/lib/umd'), main: 'main' }, { name: 'vscode-languageserver-textdocument', - location: path.join( - REPO_ROOT, - 'node_modules/vscode-languageserver-textdocument/lib/umd' - ), + location: path.join(REPO_ROOT, 'node_modules/vscode-languageserver-textdocument/lib/umd'), main: 'main' }, { @@ -80,14 +71,8 @@ function bundleOne(moduleId, exclude) { ] }, async function (buildResponse) { - const devFilePath = path.join( - REPO_ROOT, - 'release/dev/' + moduleId + '.js' - ); - const minFilePath = path.join( - REPO_ROOT, - 'release/min/' + moduleId + '.js' - ); + const devFilePath = path.join(REPO_ROOT, 'release/dev/' + moduleId + '.js'); + const minFilePath = path.join(REPO_ROOT, 'release/min/' + moduleId + '.js'); const fileContents = fs.readFileSync(devFilePath).toString(); console.log(`Minifying ${devFilePath}...`); const result = await Terser.minify(fileContents, { diff --git a/src/fillers/vscode-nls.ts b/src/fillers/vscode-nls.ts index 09cb22e0..38f7b334 100644 --- a/src/fillers/vscode-nls.ts +++ b/src/fillers/vscode-nls.ts @@ -33,11 +33,7 @@ function format(message: string, args: any[]): string { return result; } -function localize( - key: string | LocalizeInfo, - message: string, - ...args: any[] -): string { +function localize(key: string | LocalizeInfo, message: string, ...args: any[]): string { return format(message, args); } diff --git a/src/jsonMode.ts b/src/jsonMode.ts index 8cb276f8..7d66f6a0 100644 --- a/src/jsonMode.ts +++ b/src/jsonMode.ts @@ -17,9 +17,7 @@ export function setupMode(defaults: LanguageServiceDefaults): IDisposable { const client = new WorkerManager(defaults); disposables.push(client); - const worker: languageFeatures.WorkerAccessor = ( - ...uris: Uri[] - ): Promise => { + const worker: languageFeatures.WorkerAccessor = (...uris: Uri[]): Promise => { return client.getLanguageServiceWorker(...uris); }; @@ -54,10 +52,7 @@ export function setupMode(defaults: LanguageServiceDefaults): IDisposable { } if (modeConfiguration.hovers) { providers.push( - languages.registerHoverProvider( - languageId, - new languageFeatures.HoverAdapter(worker) - ) + languages.registerHoverProvider(languageId, new languageFeatures.HoverAdapter(worker)) ); } if (modeConfiguration.documentSymbols) { @@ -69,9 +64,7 @@ export function setupMode(defaults: LanguageServiceDefaults): IDisposable { ); } if (modeConfiguration.tokens) { - providers.push( - languages.setTokensProvider(languageId, createTokenizationSupport(true)) - ); + providers.push(languages.setTokensProvider(languageId, createTokenizationSupport(true))); } if (modeConfiguration.colors) { providers.push( @@ -90,9 +83,7 @@ export function setupMode(defaults: LanguageServiceDefaults): IDisposable { ); } if (modeConfiguration.diagnostics) { - providers.push( - new languageFeatures.DiagnosticsAdapter(languageId, worker, defaults) - ); + providers.push(new languageFeatures.DiagnosticsAdapter(languageId, worker, defaults)); } if (modeConfiguration.selectionRanges) { providers.push( @@ -106,12 +97,7 @@ export function setupMode(defaults: LanguageServiceDefaults): IDisposable { registerProviders(); - disposables.push( - languages.setLanguageConfiguration( - defaults.languageId, - richEditConfiguration - ) - ); + disposables.push(languages.setLanguageConfiguration(defaults.languageId, richEditConfiguration)); let modeConfiguration = defaults.modeConfiguration; defaults.onDidChange((newDefaults) => { diff --git a/src/jsonWorker.ts b/src/jsonWorker.ts index edbd901e..f069ae11 100644 --- a/src/jsonWorker.ts +++ b/src/jsonWorker.ts @@ -24,8 +24,7 @@ export class JSONWorker { this._languageSettings = createData.languageSettings; this._languageId = createData.languageId; this._languageService = jsonService.getLanguageService({ - schemaRequestService: - createData.enableSchemaRequest && defaultSchemaRequestService + schemaRequestService: createData.enableSchemaRequest && defaultSchemaRequestService }); this._languageService.configure(this._languageSettings); } @@ -46,15 +45,10 @@ export class JSONWorker { let jsonDocument = this._languageService.parseJSONDocument(document); return this._languageService.doComplete(document, position, jsonDocument); } - async doResolve( - item: jsonService.CompletionItem - ): Promise { + async doResolve(item: jsonService.CompletionItem): Promise { return this._languageService.doResolve(item); } - async doHover( - uri: string, - position: jsonService.Position - ): Promise { + async doHover(uri: string, position: jsonService.Position): Promise { let document = this._getTextDocument(uri); let jsonDocument = this._languageService.parseJSONDocument(document); return this._languageService.doHover(document, position, jsonDocument); @@ -71,26 +65,16 @@ export class JSONWorker { async resetSchema(uri: string): Promise { return Promise.resolve(this._languageService.resetSchema(uri)); } - async findDocumentSymbols( - uri: string - ): Promise { + async findDocumentSymbols(uri: string): Promise { let document = this._getTextDocument(uri); let jsonDocument = this._languageService.parseJSONDocument(document); - let symbols = this._languageService.findDocumentSymbols( - document, - jsonDocument - ); + let symbols = this._languageService.findDocumentSymbols(document, jsonDocument); return Promise.resolve(symbols); } - async findDocumentColors( - uri: string - ): Promise { + async findDocumentColors(uri: string): Promise { let document = this._getTextDocument(uri); let jsonDocument = this._languageService.parseJSONDocument(document); - let colorSymbols = this._languageService.findDocumentColors( - document, - jsonDocument - ); + let colorSymbols = this._languageService.findDocumentColors(document, jsonDocument); return Promise.resolve(colorSymbols); } async getColorPresentations( @@ -122,11 +106,7 @@ export class JSONWorker { ): Promise { let document = this._getTextDocument(uri); let jsonDocument = this._languageService.parseJSONDocument(document); - let ranges = this._languageService.getSelectionRanges( - document, - positions, - jsonDocument - ); + let ranges = this._languageService.getSelectionRanges(document, positions, jsonDocument); return Promise.resolve(ranges); } private _getTextDocument(uri: string): jsonService.TextDocument { @@ -151,9 +131,6 @@ export interface ICreateData { enableSchemaRequest: boolean; } -export function create( - ctx: worker.IWorkerContext, - createData: ICreateData -): JSONWorker { +export function create(ctx: worker.IWorkerContext, createData: ICreateData): JSONWorker { return new JSONWorker(ctx, createData); } diff --git a/src/languageFeatures.ts b/src/languageFeatures.ts index e28b8995..3c764eb8 100644 --- a/src/languageFeatures.ts +++ b/src/languageFeatures.ts @@ -140,12 +140,8 @@ function toSeverity(lsSeverity: number): MarkerSeverity { } } -function toDiagnostics( - resource: Uri, - diag: jsonService.Diagnostic -): editor.IMarkerData { - let code = - typeof diag.code === 'number' ? String(diag.code) : diag.code; +function toDiagnostics(resource: Uri, diag: jsonService.Diagnostic): editor.IMarkerData { + let code = typeof diag.code === 'number' ? String(diag.code) : diag.code; return { severity: toSeverity(diag.severity), @@ -306,9 +302,7 @@ function fromCompletionItemKind( return jsonService.CompletionItemKind.Property; } -function toTextEdit( - textEdit: jsonService.TextEdit -): editor.ISingleEditOperation { +function toTextEdit(textEdit: jsonService.TextEdit): editor.ISingleEditOperation { if (!textEdit) { return void 0; } @@ -372,13 +366,10 @@ export class CompletionAdapter implements languages.CompletionItemProvider { item.insertText = entry.textEdit.newText; } if (entry.additionalTextEdits) { - item.additionalTextEdits = entry.additionalTextEdits.map( - toTextEdit - ); + item.additionalTextEdits = entry.additionalTextEdits.map(toTextEdit); } if (entry.insertTextFormat === jsonService.InsertTextFormat.Snippet) { - item.insertTextRules = - languages.CompletionItemInsertTextRule.InsertAsSnippet; + item.insertTextRules = languages.CompletionItemInsertTextRule.InsertAsSnippet; } return item; }); @@ -422,10 +413,7 @@ function toMarkdownString( } function toMarkedStringArray( - contents: - | jsonService.MarkupContent - | jsonService.MarkedString - | jsonService.MarkedString[] + contents: jsonService.MarkupContent | jsonService.MarkedString | jsonService.MarkedString[] ): IMarkdownString[] { if (!contents) { return void 0; @@ -556,8 +544,7 @@ function fromFormattingOptions( }; } -export class DocumentFormattingEditProvider - implements languages.DocumentFormattingEditProvider { +export class DocumentFormattingEditProvider implements languages.DocumentFormattingEditProvider { constructor(private _worker: WorkerAccessor) {} public provideDocumentFormattingEdits( @@ -594,11 +581,7 @@ export class DocumentRangeFormattingEditProvider return this._worker(resource).then((worker) => { return worker - .format( - resource.toString(), - fromRange(range), - fromFormattingOptions(options) - ) + .format(resource.toString(), fromRange(range), fromFormattingOptions(options)) .then((edits) => { if (!edits || edits.length === 0) { return; @@ -640,11 +623,7 @@ export class DocumentColorAdapter implements languages.DocumentColorProvider { return this._worker(resource) .then((worker) => - worker.getColorPresentations( - resource.toString(), - info.color, - fromRange(info.range) - ) + worker.getColorPresentations(resource.toString(), info.color, fromRange(info.range)) ) .then((presentations) => { if (!presentations) { @@ -658,9 +637,7 @@ export class DocumentColorAdapter implements languages.DocumentColorProvider { item.textEdit = toTextEdit(presentation.textEdit); } if (presentation.additionalTextEdits) { - item.additionalTextEdits = presentation.additionalTextEdits.map( - toTextEdit - ); + item.additionalTextEdits = presentation.additionalTextEdits.map(toTextEdit); } return item; }); @@ -690,9 +667,7 @@ export class FoldingRangeAdapter implements languages.FoldingRangeProvider { end: range.endLine + 1 }; if (typeof range.kind !== 'undefined') { - result.kind = toFoldingRangeKind( - range.kind - ); + result.kind = toFoldingRangeKind(range.kind); } return result; }); @@ -700,9 +675,7 @@ export class FoldingRangeAdapter implements languages.FoldingRangeProvider { } } -function toFoldingRangeKind( - kind: jsonService.FoldingRangeKind -): languages.FoldingRangeKind { +function toFoldingRangeKind(kind: jsonService.FoldingRangeKind): languages.FoldingRangeKind { switch (kind) { case jsonService.FoldingRangeKind.Comment: return languages.FoldingRangeKind.Comment; @@ -725,12 +698,7 @@ export class SelectionRangeAdapter implements languages.SelectionRangeProvider { const resource = model.uri; return this._worker(resource) - .then((worker) => - worker.getSelectionRanges( - resource.toString(), - positions.map(fromPosition) - ) - ) + .then((worker) => worker.getSelectionRanges(resource.toString(), positions.map(fromPosition))) .then((selectionRanges) => { if (!selectionRanges) { return; diff --git a/src/monaco.contribution.ts b/src/monaco.contribution.ts index df17e778..dad2f101 100644 --- a/src/monaco.contribution.ts +++ b/src/monaco.contribution.ts @@ -181,15 +181,7 @@ function getMode(): Promise { languages.register({ id: 'json', - extensions: [ - '.json', - '.bowerrc', - '.jshintrc', - '.jscsrc', - '.eslintrc', - '.babelrc', - '.har' - ], + extensions: ['.json', '.bowerrc', '.jshintrc', '.jscsrc', '.eslintrc', '.babelrc', '.har'], aliases: ['JSON', 'json'], mimetypes: ['application/json'] }); diff --git a/src/tokenization.ts b/src/tokenization.ts index ab8e3e0b..39014379 100644 --- a/src/tokenization.ts +++ b/src/tokenization.ts @@ -6,19 +6,11 @@ import * as json from 'jsonc-parser'; import { languages } from './fillers/monaco-editor-core'; -export function createTokenizationSupport( - supportComments: boolean -): languages.TokensProvider { +export function createTokenizationSupport(supportComments: boolean): languages.TokensProvider { return { getInitialState: () => new JSONState(null, null), tokenize: (line, state, offsetDelta?, stopAtOffset?) => - tokenize( - supportComments, - line, - state, - offsetDelta, - stopAtOffset - ) + tokenize(supportComments, line, state, offsetDelta, stopAtOffset) }; } @@ -108,8 +100,7 @@ function tokenize( // Check that the scanner has advanced if (offset === offsetDelta + scanner.getPosition()) { throw new Error( - 'Scanner did not advance, next 3 characters are: ' + - line.substr(scanner.getPosition(), 3) + 'Scanner did not advance, next 3 characters are: ' + line.substr(scanner.getPosition(), 3) ); } diff --git a/src/tsconfig.esm.json b/src/tsconfig.esm.json index eb9d7013..b97a230f 100644 --- a/src/tsconfig.esm.json +++ b/src/tsconfig.esm.json @@ -5,12 +5,6 @@ "moduleResolution": "node", "outDir": "../out/esm", "target": "es5", - "lib": [ - "dom", - "es5", - "es2015.collection", - "es2015.promise", - "es2015.iterable" - ] + "lib": ["dom", "es5", "es2015.collection", "es2015.promise", "es2015.iterable"] } } diff --git a/src/tsconfig.json b/src/tsconfig.json index 6b43d988..707f714d 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -5,12 +5,6 @@ "outDir": "../out/amd", "declaration": true, "target": "es5", - "lib": [ - "dom", - "es5", - "es2015.collection", - "es2015.promise", - "es2015.iterable" - ] + "lib": ["dom", "es5", "es2015.collection", "es2015.promise", "es2015.iterable"] } } diff --git a/src/workerManager.ts b/src/workerManager.ts index 90b184a1..c4fd2661 100644 --- a/src/workerManager.ts +++ b/src/workerManager.ts @@ -23,9 +23,7 @@ export class WorkerManager { this._worker = null; this._idleCheckInterval = setInterval(() => this._checkIfIdle(), 30 * 1000); this._lastUsedTime = 0; - this._configChangeListener = this._defaults.onDidChange(() => - this._stopWorker() - ); + this._configChangeListener = this._defaults.onDidChange(() => this._stopWorker()); } private _stopWorker(): void { @@ -66,8 +64,7 @@ export class WorkerManager { createData: { languageSettings: this._defaults.diagnosticsOptions, languageId: this._defaults.languageId, - enableSchemaRequest: this._defaults.diagnosticsOptions - .enableSchemaRequest + enableSchemaRequest: this._defaults.diagnosticsOptions.enableSchemaRequest } }); diff --git a/test/index.html b/test/index.html index c1bb2cad..90fedaba 100644 --- a/test/index.html +++ b/test/index.html @@ -11,10 +11,7 @@

Monaco Editor JSON test page

-
+