提交 f7ed3485 编写于 作者: M Martin Aeschlimann

Update JSON service to latest vscode-languageserver

上级 c843d585
...@@ -10,10 +10,6 @@ import {workspace, languages, ExtensionContext, extensions, Uri} from 'vscode'; ...@@ -10,10 +10,6 @@ import {workspace, languages, ExtensionContext, extensions, Uri} from 'vscode';
import {LanguageClient, LanguageClientOptions, RequestType, ServerOptions, TransportKind, NotificationType} from 'vscode-languageclient'; import {LanguageClient, LanguageClientOptions, RequestType, ServerOptions, TransportKind, NotificationType} from 'vscode-languageclient';
import TelemetryReporter from 'vscode-extension-telemetry'; import TelemetryReporter from 'vscode-extension-telemetry';
namespace TelemetryNotification {
export const type: NotificationType<{ key: string, data: any }> = { get method() { return 'telemetry'; } };
}
namespace VSCodeContentRequest { namespace VSCodeContentRequest {
export const type: RequestType<string, string, any> = { get method() { return 'vscode/content'; } }; export const type: RequestType<string, string, any> = { get method() { return 'vscode/content'; } };
} }
...@@ -68,7 +64,7 @@ export function activate(context: ExtensionContext) { ...@@ -68,7 +64,7 @@ export function activate(context: ExtensionContext) {
// Create the language client and start the client. // Create the language client and start the client.
let client = new LanguageClient('JSON Server', serverOptions, clientOptions); let client = new LanguageClient('JSON Server', serverOptions, clientOptions);
client.onNotification(TelemetryNotification.type, e => { client.onTelemetry(e => {
if (telemetryReporter) { if (telemetryReporter) {
telemetryReporter.sendTelemetryEvent(e.key, e.data); telemetryReporter.sendTelemetryEvent(e.key, e.data);
} }
......
...@@ -128,7 +128,7 @@ ...@@ -128,7 +128,7 @@
} }
}, },
"dependencies": { "dependencies": {
"vscode-languageclient": "^1.3.1", "vscode-languageclient": "^2.2.1",
"vscode-extension-telemetry": "^0.0.5" "vscode-extension-telemetry": "^0.0.5"
} }
} }
\ No newline at end of file
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
"dependencies": { "dependencies": {
"request-light": "^0.1.0", "request-light": "^0.1.0",
"jsonc-parser": "^0.2.0", "jsonc-parser": "^0.2.0",
"vscode-languageserver": "^1.3.0", "vscode-languageserver": "^2.2.0",
"vscode-nls": "^1.0.4" "vscode-nls": "^1.0.4"
}, },
"scripts": { "scripts": {
......
...@@ -10,7 +10,7 @@ import SchemaService = require('./jsonSchemaService'); ...@@ -10,7 +10,7 @@ import SchemaService = require('./jsonSchemaService');
import JsonSchema = require('./jsonSchema'); import JsonSchema = require('./jsonSchema');
import {IJSONWorkerContribution} from './jsonContributions'; import {IJSONWorkerContribution} from './jsonContributions';
import {CompletionItem, CompletionItemKind, CompletionList, ITextDocument, TextDocumentPosition, Range, TextEdit, RemoteConsole} from 'vscode-languageserver'; import {CompletionItem, CompletionItemKind, CompletionList, TextDocument, Position, Range, TextEdit, RemoteConsole} from 'vscode-languageserver';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
...@@ -46,9 +46,9 @@ export class JSONCompletion { ...@@ -46,9 +46,9 @@ export class JSONCompletion {
return Promise.resolve(item); return Promise.resolve(item);
} }
public doSuggest(document: ITextDocument, textDocumentPosition: TextDocumentPosition, doc: Parser.JSONDocument): Thenable<CompletionList> { public doSuggest(document: TextDocument, position: Position, doc: Parser.JSONDocument): Thenable<CompletionList> {
let offset = document.offsetAt(textDocumentPosition.position); let offset = document.offsetAt(position);
let node = doc.getNodeFromOffsetEndInclusive(offset); let node = doc.getNodeFromOffsetEndInclusive(offset);
let currentWord = this.getCurrentWord(document, offset); let currentWord = this.getCurrentWord(document, offset);
...@@ -61,7 +61,7 @@ export class JSONCompletion { ...@@ -61,7 +61,7 @@ export class JSONCompletion {
if (node && (node.type === 'string' || node.type === 'number' || node.type === 'boolean' || node.type === 'null')) { if (node && (node.type === 'string' || node.type === 'number' || node.type === 'boolean' || node.type === 'null')) {
overwriteRange = Range.create(document.positionAt(node.start), document.positionAt(node.end)); overwriteRange = Range.create(document.positionAt(node.start), document.positionAt(node.end));
} else { } else {
overwriteRange = Range.create(document.positionAt(offset - currentWord.length), textDocumentPosition.position); overwriteRange = Range.create(document.positionAt(offset - currentWord.length), position);
} }
let proposed: { [key: string]: boolean } = {}; let proposed: { [key: string]: boolean } = {};
...@@ -87,7 +87,7 @@ export class JSONCompletion { ...@@ -87,7 +87,7 @@ export class JSONCompletion {
} }
}; };
return this.schemaService.getSchemaForResource(textDocumentPosition.uri, doc).then((schema) => { return this.schemaService.getSchemaForResource(document.uri, doc).then((schema) => {
let collectionPromises: Thenable<any>[] = []; let collectionPromises: Thenable<any>[] = [];
let addValue = true; let addValue = true;
...@@ -134,7 +134,7 @@ export class JSONCompletion { ...@@ -134,7 +134,7 @@ export class JSONCompletion {
let location = node.getNodeLocation(); let location = node.getNodeLocation();
this.contributions.forEach((contribution) => { this.contributions.forEach((contribution) => {
let collectPromise = contribution.collectPropertySuggestions(textDocumentPosition.uri, location, currentWord, addValue, isLast, collector); let collectPromise = contribution.collectPropertySuggestions(document.uri, location, currentWord, addValue, isLast, collector);
if (collectPromise) { if (collectPromise) {
collectionPromises.push(collectPromise); collectionPromises.push(collectPromise);
} }
...@@ -157,7 +157,7 @@ export class JSONCompletion { ...@@ -157,7 +157,7 @@ export class JSONCompletion {
if (!node) { if (!node) {
this.contributions.forEach((contribution) => { this.contributions.forEach((contribution) => {
let collectPromise = contribution.collectDefaultSuggestions(textDocumentPosition.uri, collector); let collectPromise = contribution.collectDefaultSuggestions(document.uri, collector);
if (collectPromise) { if (collectPromise) {
collectionPromises.push(collectPromise); collectionPromises.push(collectPromise);
} }
...@@ -170,7 +170,7 @@ export class JSONCompletion { ...@@ -170,7 +170,7 @@ export class JSONCompletion {
if (!valueNode || offset <= valueNode.end) { if (!valueNode || offset <= valueNode.end) {
let location = node.parent.getNodeLocation(); let location = node.parent.getNodeLocation();
this.contributions.forEach((contribution) => { this.contributions.forEach((contribution) => {
let collectPromise = contribution.collectValueSuggestions(textDocumentPosition.uri, location, parentKey, collector); let collectPromise = contribution.collectValueSuggestions(document.uri, location, parentKey, collector);
if (collectPromise) { if (collectPromise) {
collectionPromises.push(collectPromise); collectionPromises.push(collectPromise);
} }
...@@ -230,7 +230,7 @@ export class JSONCompletion { ...@@ -230,7 +230,7 @@ export class JSONCompletion {
} }
} }
private getSchemaLessValueSuggestions(doc: Parser.JSONDocument, node: Parser.ASTNode, offset: number, document: ITextDocument, collector: ISuggestionsCollector): void { private getSchemaLessValueSuggestions(doc: Parser.JSONDocument, node: Parser.ASTNode, offset: number, document: TextDocument, collector: ISuggestionsCollector): void {
let collectSuggestionsForValues = (value: Parser.ASTNode) => { let collectSuggestionsForValues = (value: Parser.ASTNode) => {
if (!value.contains(offset)) { if (!value.contains(offset)) {
let content = this.getTextForMatchingNode(value, document); let content = this.getTextForMatchingNode(value, document);
...@@ -449,7 +449,7 @@ export class JSONCompletion { ...@@ -449,7 +449,7 @@ export class JSONCompletion {
} }
private getTextForMatchingNode(node: Parser.ASTNode, document: ITextDocument): string { private getTextForMatchingNode(node: Parser.ASTNode, document: TextDocument): string {
switch (node.type) { switch (node.type) {
case 'array': case 'array':
return '[]'; return '[]';
...@@ -513,7 +513,7 @@ export class JSONCompletion { ...@@ -513,7 +513,7 @@ export class JSONCompletion {
return this.getTextForValue(key); return this.getTextForValue(key);
} }
private getCurrentWord(document: ITextDocument, offset: number) { private getCurrentWord(document: TextDocument, offset: number) {
var i = offset - 1; var i = offset - 1;
var text = document.getText(); var text = document.getText();
while (i >= 0 && ' \t\n\r\v":{[,'.indexOf(text.charAt(i)) === -1) { while (i >= 0 && ' \t\n\r\v":{[,'.indexOf(text.charAt(i)) === -1) {
......
...@@ -7,14 +7,14 @@ ...@@ -7,14 +7,14 @@
import Parser = require('./jsonParser'); import Parser = require('./jsonParser');
import Strings = require('./utils/strings'); import Strings = require('./utils/strings');
import {SymbolInformation, SymbolKind, ITextDocument, Range, Location} from 'vscode-languageserver'; import {SymbolInformation, SymbolKind, TextDocument, Range, Location} from 'vscode-languageserver';
export class JSONDocumentSymbols { export class JSONDocumentSymbols {
constructor() { constructor() {
} }
public compute(document: ITextDocument, doc: Parser.JSONDocument): Promise<SymbolInformation[]> { public compute(document: TextDocument, doc: Parser.JSONDocument): Promise<SymbolInformation[]> {
let root = doc.root; let root = doc.root;
if (!root) { if (!root) {
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
'use strict'; 'use strict';
import Json = require('jsonc-parser'); import Json = require('jsonc-parser');
import {ITextDocument, Range, Position, FormattingOptions, TextEdit} from 'vscode-languageserver'; import {TextDocument, Range, Position, FormattingOptions, TextEdit} from 'vscode-languageserver';
export function format(document: ITextDocument, range: Range, options: FormattingOptions): TextEdit[] { export function format(document: TextDocument, range: Range, options: FormattingOptions): TextEdit[] {
const documentText = document.getText(); const documentText = document.getText();
let initialIndentLevel: number; let initialIndentLevel: number;
let value: string; let value: string;
...@@ -83,7 +83,7 @@ export function format(document: ITextDocument, range: Range, options: Formattin ...@@ -83,7 +83,7 @@ export function format(document: ITextDocument, range: Range, options: Formattin
replaceContent = secondToken === Json.SyntaxKind.LineCommentTrivia ? newLineAndIndent() : ''; replaceContent = secondToken === Json.SyntaxKind.LineCommentTrivia ? newLineAndIndent() : '';
secondToken = scanNext(); secondToken = scanNext();
} }
if (secondToken === Json.SyntaxKind.CloseBraceToken) { if (secondToken === Json.SyntaxKind.CloseBraceToken) {
if (firstToken !== Json.SyntaxKind.OpenBraceToken) { if (firstToken !== Json.SyntaxKind.OpenBraceToken) {
indentLevel--; indentLevel--;
...@@ -163,7 +163,7 @@ function computeIndentLevel(content: string, offset: number, options: Formatting ...@@ -163,7 +163,7 @@ function computeIndentLevel(content: string, offset: number, options: Formatting
return Math.floor(nChars / tabSize); return Math.floor(nChars / tabSize);
} }
function getEOL(document: ITextDocument): string { function getEOL(document: TextDocument): string {
let text = document.getText(); let text = document.getText();
if (document.lineCount > 1) { if (document.lineCount > 1) {
let to = document.offsetAt(Position.create(1, 0)); let to = document.offsetAt(Position.create(1, 0));
......
...@@ -9,7 +9,7 @@ import Parser = require('./jsonParser'); ...@@ -9,7 +9,7 @@ import Parser = require('./jsonParser');
import SchemaService = require('./jsonSchemaService'); import SchemaService = require('./jsonSchemaService');
import {IJSONWorkerContribution} from './jsonContributions'; import {IJSONWorkerContribution} from './jsonContributions';
import {Hover, ITextDocument, TextDocumentPosition, Range, MarkedString} from 'vscode-languageserver'; import {Hover, TextDocument, Position, Range, MarkedString} from 'vscode-languageserver';
export class JSONHover { export class JSONHover {
...@@ -21,9 +21,9 @@ export class JSONHover { ...@@ -21,9 +21,9 @@ export class JSONHover {
this.contributions = contributions; this.contributions = contributions;
} }
public doHover(document: ITextDocument, textDocumentPosition: TextDocumentPosition, doc: Parser.JSONDocument): Thenable<Hover> { public doHover(document: TextDocument, position: Position, doc: Parser.JSONDocument): Thenable<Hover> {
let offset = document.offsetAt(textDocumentPosition.position); let offset = document.offsetAt(position);
let node = doc.getNodeFromOffset(offset); let node = doc.getNodeFromOffset(offset);
// use the property description when hovering over an object key // use the property description when hovering over an object key
...@@ -39,7 +39,7 @@ export class JSONHover { ...@@ -39,7 +39,7 @@ export class JSONHover {
if (!node) { if (!node) {
return Promise.resolve(void 0); return Promise.resolve(void 0);
} }
var createHover = (contents: MarkedString[]) => { var createHover = (contents: MarkedString[]) => {
let range = Range.create(document.positionAt(node.start), document.positionAt(node.end)); let range = Range.create(document.positionAt(node.start), document.positionAt(node.end));
let result: Hover = { let result: Hover = {
...@@ -47,18 +47,18 @@ export class JSONHover { ...@@ -47,18 +47,18 @@ export class JSONHover {
range: range range: range
}; };
return result; return result;
}; };
let location = node.getNodeLocation(); let location = node.getNodeLocation();
for (let i = this.contributions.length - 1; i >= 0; i--) { for (let i = this.contributions.length - 1; i >= 0; i--) {
let contribution = this.contributions[i]; let contribution = this.contributions[i];
let promise = contribution.getInfoContribution(textDocumentPosition.uri, location); let promise = contribution.getInfoContribution(document.uri, location);
if (promise) { if (promise) {
return promise.then(htmlContent => createHover(htmlContent)); return promise.then(htmlContent => createHover(htmlContent));
} }
} }
return this.schemaService.getSchemaForResource(textDocumentPosition.uri, doc).then((schema) => { return this.schemaService.getSchemaForResource(document.uri, doc).then((schema) => {
if (schema) { if (schema) {
let matchingSchemas: Parser.IApplicableSchema[] = []; let matchingSchemas: Parser.IApplicableSchema[] = [];
doc.validate(schema.schema, matchingSchemas, node.start); doc.validate(schema.schema, matchingSchemas, node.start);
......
...@@ -5,11 +5,10 @@ ...@@ -5,11 +5,10 @@
'use strict'; 'use strict';
import { import {
IPCMessageReader, IPCMessageWriter, IPCMessageReader, IPCMessageWriter, createConnection, IConnection,
createConnection, IConnection, TextDocuments, TextDocument, Diagnostic, DiagnosticSeverity,
TextDocuments, ITextDocument, Diagnostic, DiagnosticSeverity, InitializeParams, InitializeResult, TextDocumentPositionParams, CompletionList,
InitializeParams, InitializeResult, TextDocumentIdentifier, TextDocumentPosition, CompletionList, CompletionItem, Hover, SymbolInformation, DocumentFormattingParams, DocumentSymbolParams,
CompletionItem, Hover, SymbolInformation, DocumentFormattingParams,
DocumentRangeFormattingParams, NotificationType, RequestType DocumentRangeFormattingParams, NotificationType, RequestType
} from 'vscode-languageserver'; } from 'vscode-languageserver';
...@@ -33,10 +32,6 @@ import {FileAssociationContribution} from './jsoncontributions/fileAssociationCo ...@@ -33,10 +32,6 @@ import {FileAssociationContribution} from './jsoncontributions/fileAssociationCo
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
nls.config(process.env['VSCODE_NLS_CONFIG']); nls.config(process.env['VSCODE_NLS_CONFIG']);
namespace TelemetryNotification {
export const type: NotificationType<{ key: string, data: any }> = { get method() { return 'telemetry'; } };
}
namespace SchemaAssociationNotification { namespace SchemaAssociationNotification {
export const type: NotificationType<ISchemaAssociations> = { get method() { return 'json/schemaAssociations'; } }; export const type: NotificationType<ISchemaAssociations> = { get method() { return 'json/schemaAssociations'; } };
} }
...@@ -89,7 +84,7 @@ let workspaceContext = { ...@@ -89,7 +84,7 @@ let workspaceContext = {
let telemetry = { let telemetry = {
log: (key: string, data: any) => { log: (key: string, data: any) => {
connection.sendNotification(TelemetryNotification.type, { key, data }); connection.telemetry.logEvent({ key, data });
} }
}; };
...@@ -208,7 +203,7 @@ function updateConfiguration() { ...@@ -208,7 +203,7 @@ function updateConfiguration() {
} }
function validateTextDocument(textDocument: ITextDocument): void { function validateTextDocument(textDocument: TextDocument): void {
if (textDocument.getText().length === 0) { if (textDocument.getText().length === 0) {
// ignore empty documents // ignore empty documents
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: [] }); connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: [] });
...@@ -268,28 +263,28 @@ connection.onDidChangeWatchedFiles((change) => { ...@@ -268,28 +263,28 @@ connection.onDidChangeWatchedFiles((change) => {
} }
}); });
function getJSONDocument(document: ITextDocument): JSONDocument { function getJSONDocument(document: TextDocument): JSONDocument {
return parseJSON(document.getText()); return parseJSON(document.getText());
} }
connection.onCompletion((textDocumentPosition: TextDocumentPosition): Thenable<CompletionList> => { connection.onCompletion((textDocumentPosition: TextDocumentPositionParams): Thenable<CompletionList> => {
let document = documents.get(textDocumentPosition.uri); let document = documents.get(textDocumentPosition.textDocument.uri);
let jsonDocument = getJSONDocument(document); let jsonDocument = getJSONDocument(document);
return jsonCompletion.doSuggest(document, textDocumentPosition, jsonDocument); return jsonCompletion.doSuggest(document, textDocumentPosition.position, jsonDocument);
}); });
connection.onCompletionResolve((item: CompletionItem) : Thenable<CompletionItem> => { connection.onCompletionResolve((item: CompletionItem) : Thenable<CompletionItem> => {
return jsonCompletion.doResolve(item); return jsonCompletion.doResolve(item);
}); });
connection.onHover((textDocumentPosition: TextDocumentPosition): Thenable<Hover> => { connection.onHover((textDocumentPosition: TextDocumentPositionParams): Thenable<Hover> => {
let document = documents.get(textDocumentPosition.uri); let document = documents.get(textDocumentPosition.textDocument.uri);
let jsonDocument = getJSONDocument(document); let jsonDocument = getJSONDocument(document);
return jsonHover.doHover(document, textDocumentPosition, jsonDocument); return jsonHover.doHover(document, textDocumentPosition.position, jsonDocument);
}); });
connection.onDocumentSymbol((textDocumentIdentifier: TextDocumentIdentifier): Thenable<SymbolInformation[]> => { connection.onDocumentSymbol((documentSymbolParams: DocumentSymbolParams): Thenable<SymbolInformation[]> => {
let document = documents.get(textDocumentIdentifier.uri); let document = documents.get(documentSymbolParams.textDocument.uri);
let jsonDocument = getJSONDocument(document); let jsonDocument = getJSONDocument(document);
return jsonDocumentSymbols.compute(document, jsonDocument); return jsonDocumentSymbols.compute(document, jsonDocument);
}); });
......
...@@ -11,7 +11,7 @@ import JsonSchema = require('../jsonSchema'); ...@@ -11,7 +11,7 @@ import JsonSchema = require('../jsonSchema');
import {JSONCompletion} from '../jsonCompletion'; import {JSONCompletion} from '../jsonCompletion';
import {XHROptions, XHRResponse} from 'request-light'; import {XHROptions, XHRResponse} from 'request-light';
import {CompletionItem, CompletionItemKind, CompletionOptions, ITextDocument, TextDocumentIdentifier, TextDocumentPosition, Range, Position, TextEdit} from 'vscode-languageserver'; import {CompletionItem, CompletionItemKind, CompletionOptions, TextDocument, TextDocumentIdentifier, Range, Position, TextEdit} from 'vscode-languageserver';
import {applyEdits} from './textEditSupport'; import {applyEdits} from './textEditSupport';
suite('JSON Completion', () => { suite('JSON Completion', () => {
...@@ -20,7 +20,7 @@ suite('JSON Completion', () => { ...@@ -20,7 +20,7 @@ suite('JSON Completion', () => {
return Promise.reject<XHRResponse>({ responseText: '', status: 404 }); return Promise.reject<XHRResponse>({ responseText: '', status: 404 });
} }
var assertSuggestion = function(completions: CompletionItem[], label: string, documentation?: string, document?: ITextDocument, resultText?: string) { var assertSuggestion = function(completions: CompletionItem[], label: string, documentation?: string, document?: TextDocument, resultText?: string) {
var matches = completions.filter(function(completion: CompletionItem) { var matches = completions.filter(function(completion: CompletionItem) {
return completion.label === label && (!documentation || completion.documentation === documentation); return completion.label === label && (!documentation || completion.documentation === documentation);
}); });
...@@ -31,7 +31,7 @@ suite('JSON Completion', () => { ...@@ -31,7 +31,7 @@ suite('JSON Completion', () => {
}; };
var testSuggestionsFor = function(value: string, stringAfter: string, schema: JsonSchema.IJSONSchema, test: (items: CompletionItem[], document: ITextDocument) => void) : Thenable<void> { var testSuggestionsFor = function(value: string, stringAfter: string, schema: JsonSchema.IJSONSchema, test: (items: CompletionItem[], document: TextDocument) => void) : Thenable<void> {
var uri = 'test://test.json'; var uri = 'test://test.json';
var idx = stringAfter ? value.indexOf(stringAfter) : 0; var idx = stringAfter ? value.indexOf(stringAfter) : 0;
...@@ -42,10 +42,10 @@ suite('JSON Completion', () => { ...@@ -42,10 +42,10 @@ suite('JSON Completion', () => {
schemaService.registerExternalSchema(id, ["*.json"], schema); schemaService.registerExternalSchema(id, ["*.json"], schema);
} }
var document = ITextDocument.create(uri, value); var document = TextDocument.create(uri, 'json', 0, value);
var textDocumentLocation = TextDocumentPosition.create(uri, Position.create(0, idx)); var position = Position.create(0, idx);
var jsonDoc = Parser.parse(value); var jsonDoc = Parser.parse(value);
return completionProvider.doSuggest(document, textDocumentLocation, jsonDoc).then(list => list.items).then(completions => { return completionProvider.doSuggest(document, position, jsonDoc).then(list => list.items).then(completions => {
test(completions, document); test(completions, document);
return null; return null;
}) })
......
...@@ -11,7 +11,7 @@ import JsonSchema = require('../jsonSchema'); ...@@ -11,7 +11,7 @@ import JsonSchema = require('../jsonSchema');
import {JSONCompletion} from '../jsonCompletion'; import {JSONCompletion} from '../jsonCompletion';
import {JSONDocumentSymbols} from '../jsonDocumentSymbols'; import {JSONDocumentSymbols} from '../jsonDocumentSymbols';
import {SymbolInformation, SymbolKind, TextDocumentIdentifier, ITextDocument, TextDocumentPosition, Range, Position, TextEdit} from 'vscode-languageserver'; import {SymbolInformation, SymbolKind, TextDocumentIdentifier, TextDocument, Range, Position, TextEdit} from 'vscode-languageserver';
suite('JSON Document Symbols', () => { suite('JSON Document Symbols', () => {
...@@ -20,7 +20,7 @@ suite('JSON Document Symbols', () => { ...@@ -20,7 +20,7 @@ suite('JSON Document Symbols', () => {
var symbolProvider = new JSONDocumentSymbols(); var symbolProvider = new JSONDocumentSymbols();
var document = ITextDocument.create(uri, value); var document = TextDocument.create(uri, 'json', 0, value);
var jsonDoc = Parser.parse(value); var jsonDoc = Parser.parse(value);
return symbolProvider.compute(document, jsonDoc); return symbolProvider.compute(document, jsonDoc);
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
'use strict'; 'use strict';
import Json = require('jsonc-parser'); import Json = require('jsonc-parser');
import {ITextDocument, DocumentFormattingParams, Range, Position, FormattingOptions, TextEdit} from 'vscode-languageserver'; import {TextDocument, DocumentFormattingParams, Range, Position, FormattingOptions, TextEdit} from 'vscode-languageserver';
import Formatter = require('../jsonFormatter'); import Formatter = require('../jsonFormatter');
import assert = require('assert'); import assert = require('assert');
import {applyEdits} from './textEditSupport'; import {applyEdits} from './textEditSupport';
...@@ -20,14 +20,14 @@ suite('JSON Formatter', () => { ...@@ -20,14 +20,14 @@ suite('JSON Formatter', () => {
let rangeEnd = unformatted.lastIndexOf('|'); let rangeEnd = unformatted.lastIndexOf('|');
if (rangeStart !== -1 && rangeEnd !== -1) { if (rangeStart !== -1 && rangeEnd !== -1) {
// remove '|' // remove '|'
var unformattedDoc = ITextDocument.create(uri, unformatted); var unformattedDoc = TextDocument.create(uri, 'json', 0, unformatted);
unformatted = unformatted.substring(0, rangeStart) + unformatted.substring(rangeStart + 1, rangeEnd) + unformatted.substring(rangeEnd + 1); unformatted = unformatted.substring(0, rangeStart) + unformatted.substring(rangeStart + 1, rangeEnd) + unformatted.substring(rangeEnd + 1);
let startPos = unformattedDoc.positionAt(rangeStart); let startPos = unformattedDoc.positionAt(rangeStart);
let endPos = unformattedDoc.positionAt(rangeEnd); let endPos = unformattedDoc.positionAt(rangeEnd);
range = Range.create(startPos, endPos); range = Range.create(startPos, endPos);
} }
var document = ITextDocument.create(uri, unformatted); var document = TextDocument.create(uri, 'json', 0, unformatted);
let edits = Formatter.format(document, range, { tabSize: 2, insertSpaces: insertSpaces }); let edits = Formatter.format(document, range, { tabSize: 2, insertSpaces: insertSpaces });
let formatted = applyEdits(document, edits); let formatted = applyEdits(document, edits);
assert.equal(formatted, expected); assert.equal(formatted, expected);
...@@ -308,7 +308,7 @@ suite('JSON Formatter', () => { ...@@ -308,7 +308,7 @@ suite('JSON Formatter', () => {
format(content, expected); format(content, expected);
}); });
test('multiple mixed comments on same line', () => { test('multiple mixed comments on same line', () => {
var content = [ var content = [
'[ /*comment*/ /*comment*/ // comment ', '[ /*comment*/ /*comment*/ // comment ',
......
...@@ -12,7 +12,7 @@ import {JSONCompletion} from '../jsonCompletion'; ...@@ -12,7 +12,7 @@ import {JSONCompletion} from '../jsonCompletion';
import {XHROptions, XHRResponse} from 'request-light'; import {XHROptions, XHRResponse} from 'request-light';
import {JSONHover} from '../jsonHover'; import {JSONHover} from '../jsonHover';
import {Hover, ITextDocument, TextDocumentIdentifier, TextDocumentPosition, Range, Position, TextEdit} from 'vscode-languageserver'; import {Hover, TextDocument, TextDocumentIdentifier, TextDocumentPositionParams, Range, Position, TextEdit} from 'vscode-languageserver';
suite('JSON Hover', () => { suite('JSON Hover', () => {
...@@ -24,10 +24,9 @@ suite('JSON Hover', () => { ...@@ -24,10 +24,9 @@ suite('JSON Hover', () => {
var id = "http://myschemastore/test1"; var id = "http://myschemastore/test1";
schemaService.registerExternalSchema(id, ["*.json"], schema); schemaService.registerExternalSchema(id, ["*.json"], schema);
var document = ITextDocument.create(uri, value); var document = TextDocument.create(uri, 'json', 0, value);
var textDocumentLocation = TextDocumentPosition.create(uri, position);
var jsonDoc = Parser.parse(value); var jsonDoc = Parser.parse(value);
return hoverProvider.doHover(document, textDocumentLocation, jsonDoc); return hoverProvider.doHover(document, position, jsonDoc);
} }
var requestService = function(options: XHROptions): Promise<XHRResponse> { var requestService = function(options: XHROptions): Promise<XHRResponse> {
......
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
'use strict'; 'use strict';
import {ITextDocument, TextEdit} from 'vscode-languageserver'; import {TextDocument, TextEdit} from 'vscode-languageserver';
import assert = require('assert'); import assert = require('assert');
export function applyEdits(document: ITextDocument, edits: TextEdit[]) : string { export function applyEdits(document: TextDocument, edits: TextEdit[]) : string {
let formatted = document.getText(); let formatted = document.getText();
let sortedEdits = edits.sort((a, b) => document.offsetAt(b.range.start) - document.offsetAt(a.range.start)); let sortedEdits = edits.sort((a, b) => document.offsetAt(b.range.start) - document.offsetAt(a.range.start));
let lastOffset = formatted.length; let lastOffset = formatted.length;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册