mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 19:18:59 +01:00
Update JSON service to latest vscode-languageserver
This commit is contained in:
@@ -11,7 +11,7 @@ import JsonSchema = require('../jsonSchema');
|
||||
import {JSONCompletion} from '../jsonCompletion';
|
||||
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';
|
||||
|
||||
suite('JSON Completion', () => {
|
||||
@@ -20,7 +20,7 @@ suite('JSON Completion', () => {
|
||||
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) {
|
||||
return completion.label === label && (!documentation || completion.documentation === documentation);
|
||||
});
|
||||
@@ -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 idx = stringAfter ? value.indexOf(stringAfter) : 0;
|
||||
|
||||
@@ -42,10 +42,10 @@ suite('JSON Completion', () => {
|
||||
schemaService.registerExternalSchema(id, ["*.json"], schema);
|
||||
}
|
||||
|
||||
var document = ITextDocument.create(uri, value);
|
||||
var textDocumentLocation = TextDocumentPosition.create(uri, Position.create(0, idx));
|
||||
var document = TextDocument.create(uri, 'json', 0, value);
|
||||
var position = Position.create(0, idx);
|
||||
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);
|
||||
return null;
|
||||
})
|
||||
|
||||
@@ -11,7 +11,7 @@ import JsonSchema = require('../jsonSchema');
|
||||
import {JSONCompletion} from '../jsonCompletion';
|
||||
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', () => {
|
||||
|
||||
@@ -20,7 +20,7 @@ suite('JSON Document Symbols', () => {
|
||||
|
||||
var symbolProvider = new JSONDocumentSymbols();
|
||||
|
||||
var document = ITextDocument.create(uri, value);
|
||||
var document = TextDocument.create(uri, 'json', 0, value);
|
||||
var jsonDoc = Parser.parse(value);
|
||||
return symbolProvider.compute(document, jsonDoc);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
'use strict';
|
||||
|
||||
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 assert = require('assert');
|
||||
import {applyEdits} from './textEditSupport';
|
||||
@@ -20,14 +20,14 @@ suite('JSON Formatter', () => {
|
||||
let rangeEnd = unformatted.lastIndexOf('|');
|
||||
if (rangeStart !== -1 && rangeEnd !== -1) {
|
||||
// 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);
|
||||
let startPos = unformattedDoc.positionAt(rangeStart);
|
||||
let endPos = unformattedDoc.positionAt(rangeEnd);
|
||||
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 formatted = applyEdits(document, edits);
|
||||
assert.equal(formatted, expected);
|
||||
@@ -308,7 +308,7 @@ suite('JSON Formatter', () => {
|
||||
|
||||
format(content, expected);
|
||||
});
|
||||
|
||||
|
||||
test('multiple mixed comments on same line', () => {
|
||||
var content = [
|
||||
'[ /*comment*/ /*comment*/ // comment ',
|
||||
|
||||
@@ -12,7 +12,7 @@ import {JSONCompletion} from '../jsonCompletion';
|
||||
import {XHROptions, XHRResponse} from 'request-light';
|
||||
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', () => {
|
||||
|
||||
@@ -24,10 +24,9 @@ suite('JSON Hover', () => {
|
||||
var id = "http://myschemastore/test1";
|
||||
schemaService.registerExternalSchema(id, ["*.json"], schema);
|
||||
|
||||
var document = ITextDocument.create(uri, value);
|
||||
var textDocumentLocation = TextDocumentPosition.create(uri, position);
|
||||
var document = TextDocument.create(uri, 'json', 0, 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> {
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import {ITextDocument, TextEdit} from 'vscode-languageserver';
|
||||
import {TextDocument, TextEdit} from 'vscode-languageserver';
|
||||
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 sortedEdits = edits.sort((a, b) => document.offsetAt(b.range.start) - document.offsetAt(a.range.start));
|
||||
let lastOffset = formatted.length;
|
||||
|
||||
Reference in New Issue
Block a user