mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Update deps, remove applyEdits
This commit is contained in:
parent
0ae6c19a60
commit
e394797455
|
@ -8,9 +8,9 @@
|
|||
"node": "*"
|
||||
},
|
||||
"dependencies": {
|
||||
"vscode-css-languageservice": "^3.0.7",
|
||||
"vscode-css-languageservice": "^3.0.9-next.1",
|
||||
"vscode-emmet-helper": "^1.2.0",
|
||||
"vscode-languageserver": "4.0.0-next.4"
|
||||
"vscode-languageserver": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/mocha": "2.2.33",
|
||||
|
|
|
@ -5,19 +5,16 @@
|
|||
'use strict';
|
||||
|
||||
import {
|
||||
createConnection, IConnection, TextDocuments, InitializeParams, InitializeResult, ServerCapabilities
|
||||
createConnection, IConnection, TextDocuments, InitializeParams, InitializeResult, ServerCapabilities,
|
||||
ConfigurationRequest, WorkspaceFolder, DocumentColorRequest, ColorPresentationRequest
|
||||
} from 'vscode-languageserver';
|
||||
|
||||
import { TextDocument, CompletionList } from 'vscode-languageserver-types';
|
||||
|
||||
import { ConfigurationRequest } from 'vscode-languageserver-protocol/lib/protocol.configuration.proposed';
|
||||
import { WorkspaceFolder } from 'vscode-languageserver-protocol/lib/protocol.workspaceFolders.proposed';
|
||||
import { DocumentColorRequest, ServerCapabilities as CPServerCapabilities, ColorPresentationRequest } from 'vscode-languageserver-protocol/lib/protocol.colorProvider.proposed';
|
||||
|
||||
import { getCSSLanguageService, getSCSSLanguageService, getLESSLanguageService, LanguageSettings, LanguageService, Stylesheet } from 'vscode-css-languageservice';
|
||||
import { getLanguageModelCache } from './languageModelCache';
|
||||
import { formatError, runSafe } from './utils/errors';
|
||||
import uri from 'vscode-uri';
|
||||
import URI from 'vscode-uri';
|
||||
import { getPathCompletionParticipant } from './pathCompletion';
|
||||
|
||||
export interface Settings {
|
||||
|
@ -61,7 +58,7 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
|
|||
if (!Array.isArray(workspaceFolders)) {
|
||||
workspaceFolders = [];
|
||||
if (params.rootPath) {
|
||||
workspaceFolders.push({ name: '', uri: uri.file(params.rootPath).toString() });
|
||||
workspaceFolders.push({ name: '', uri: URI.file(params.rootPath).toString() });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +72,7 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
|
|||
}
|
||||
let snippetSupport = hasClientCapability('textDocument.completion.completionItem.snippetSupport');
|
||||
scopedSettingsSupport = hasClientCapability('workspace.configuration');
|
||||
let capabilities: ServerCapabilities & CPServerCapabilities = {
|
||||
let capabilities: ServerCapabilities = {
|
||||
// Tell the client that the server works in FULL text document sync mode
|
||||
textDocumentSync: documents.syncKind,
|
||||
completionProvider: snippetSupport ? { resolveProvider: false } : undefined,
|
||||
|
@ -191,7 +188,7 @@ connection.onCompletion(textDocumentPosition => {
|
|||
items: []
|
||||
};
|
||||
cssLS.setCompletionParticipants([getPathCompletionParticipant(document, workspaceFolders, pathCompletionList)]);
|
||||
const result = getLanguageService(document).doComplete(document, textDocumentPosition.position, stylesheets.get(document))!; /* TODO: remove ! once LS has null annotations */
|
||||
const result = cssLS.doComplete(document, textDocumentPosition.position, stylesheets.get(document))!; /* TODO: remove ! once LS has null annotations */
|
||||
return {
|
||||
isIncomplete: result.isIncomplete,
|
||||
items: [...pathCompletionList.items, ...result.items]
|
||||
|
|
|
@ -4,17 +4,19 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { TextDocument, CompletionList, CompletionItemKind, CompletionItem, TextEdit, Range, Position } from 'vscode-languageserver-types';
|
||||
import { Proposed } from 'vscode-languageserver-protocol';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import URI from 'vscode-uri';
|
||||
import { ICompletionParticipant } from 'vscode-css-languageservice/lib/umd/cssLanguageService';
|
||||
|
||||
import { TextDocument, CompletionList, CompletionItemKind, CompletionItem, TextEdit, Range, Position } from 'vscode-languageserver-types';
|
||||
import { WorkspaceFolder } from 'vscode-languageserver';
|
||||
import { ICompletionParticipant } from 'vscode-css-languageservice';
|
||||
|
||||
import { startsWith } from './utils/strings';
|
||||
|
||||
export function getPathCompletionParticipant(
|
||||
document: TextDocument,
|
||||
workspaceFolders: Proposed.WorkspaceFolder[] | undefined,
|
||||
workspaceFolders: WorkspaceFolder[] | undefined,
|
||||
result: CompletionList
|
||||
): ICompletionParticipant {
|
||||
return {
|
||||
|
@ -92,7 +94,7 @@ const isDir = (p: string) => {
|
|||
return fs.statSync(p).isDirectory();
|
||||
};
|
||||
|
||||
function resolveWorkspaceRoot(activeDoc: TextDocument, workspaceFolders: Proposed.WorkspaceFolder[]): string | undefined {
|
||||
function resolveWorkspaceRoot(activeDoc: TextDocument, workspaceFolders: WorkspaceFolder[]): string | undefined {
|
||||
for (let i = 0; i < workspaceFolders.length; i++) {
|
||||
if (startsWith(activeDoc.uri, workspaceFolders[i].uri)) {
|
||||
return path.resolve(URI.parse(workspaceFolders[i].uri).fsPath);
|
||||
|
|
|
@ -9,10 +9,9 @@ import * as assert from 'assert';
|
|||
import * as path from 'path';
|
||||
import Uri from 'vscode-uri';
|
||||
import { TextDocument, CompletionList } from 'vscode-languageserver-types';
|
||||
import { applyEdits } from '../utils/edits';
|
||||
import { WorkspaceFolder } from 'vscode-languageserver-protocol';
|
||||
import { getPathCompletionParticipant } from '../pathCompletion';
|
||||
import { Proposed } from 'vscode-languageserver-protocol';
|
||||
import { getCSSLanguageService } from 'vscode-css-languageservice/lib/umd/cssLanguageService';
|
||||
import { getCSSLanguageService } from 'vscode-css-languageservice';
|
||||
|
||||
export interface ItemDescription {
|
||||
label: string;
|
||||
|
@ -30,11 +29,11 @@ suite('Completions', () => {
|
|||
assert.equal(matches.length, 1, `${expected.label} should only existing once: Actual: ${completions.items.map(c => c.label).join(', ')}`);
|
||||
let match = matches[0];
|
||||
if (expected.resultText && match.textEdit) {
|
||||
assert.equal(applyEdits(document, [match.textEdit]), expected.resultText);
|
||||
assert.equal(TextDocument.applyEdits(document, [match.textEdit]), expected.resultText);
|
||||
}
|
||||
};
|
||||
|
||||
function assertCompletions(value: string, expected: { count?: number, items?: ItemDescription[] }, testUri: string, workspaceFolders?: Proposed.WorkspaceFolder[]): void {
|
||||
function assertCompletions(value: string, expected: { count?: number, items?: ItemDescription[] }, testUri: string, workspaceFolders?: WorkspaceFolder[]): void {
|
||||
const offset = value.indexOf('|');
|
||||
value = value.substr(0, offset) + value.substr(offset + 1);
|
||||
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
export function pushAll<T>(to: T[], from: T[]) {
|
||||
if (from) {
|
||||
for (var i = 0; i < from.length; i++) {
|
||||
to.push(from[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function contains<T>(arr: T[], val: T) {
|
||||
return arr.indexOf(val) !== -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Like `Array#sort` but always stable. Usually runs a little slower `than Array#sort`
|
||||
* so only use this when actually needing stable sort.
|
||||
*/
|
||||
export function mergeSort<T>(data: T[], compare: (a: T, b: T) => number): T[] {
|
||||
_divideAndMerge(data, compare);
|
||||
return data;
|
||||
}
|
||||
|
||||
function _divideAndMerge<T>(data: T[], compare: (a: T, b: T) => number): void {
|
||||
if (data.length <= 1) {
|
||||
// sorted
|
||||
return;
|
||||
}
|
||||
const p = (data.length / 2) | 0;
|
||||
const left = data.slice(0, p);
|
||||
const right = data.slice(p);
|
||||
|
||||
_divideAndMerge(left, compare);
|
||||
_divideAndMerge(right, compare);
|
||||
|
||||
let leftIdx = 0;
|
||||
let rightIdx = 0;
|
||||
let i = 0;
|
||||
while (leftIdx < left.length && rightIdx < right.length) {
|
||||
let ret = compare(left[leftIdx], right[rightIdx]);
|
||||
if (ret <= 0) {
|
||||
// smaller_equal -> take left to preserve order
|
||||
data[i++] = left[leftIdx++];
|
||||
} else {
|
||||
// greater -> take right
|
||||
data[i++] = right[rightIdx++];
|
||||
}
|
||||
}
|
||||
while (leftIdx < left.length) {
|
||||
data[i++] = left[leftIdx++];
|
||||
}
|
||||
while (rightIdx < right.length) {
|
||||
data[i++] = right[rightIdx++];
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { TextDocument, TextEdit } from 'vscode-languageserver-types';
|
||||
import { mergeSort } from './arrays';
|
||||
|
||||
export function applyEdits(document: TextDocument, edits: TextEdit[]): string {
|
||||
let text = document.getText();
|
||||
let sortedEdits = mergeSort(edits, (a, b) => {
|
||||
let diff = a.range.start.line - b.range.start.line;
|
||||
if (diff === 0) {
|
||||
return a.range.start.character - b.range.start.character;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
let lastModifiedOffset = text.length;
|
||||
for (let i = sortedEdits.length - 1; i >= 0; i--) {
|
||||
let e = sortedEdits[i];
|
||||
let startOffset = document.offsetAt(e.range.start);
|
||||
let endOffset = document.offsetAt(e.range.end);
|
||||
if (endOffset <= lastModifiedOffset) {
|
||||
text = text.substring(0, startOffset) + e.newText + text.substring(endOffset, text.length);
|
||||
} else {
|
||||
throw new Error('Ovelapping edit');
|
||||
}
|
||||
lastModifiedOffset = startOffset;
|
||||
}
|
||||
return text;
|
||||
}
|
|
@ -18,12 +18,12 @@ jsonc-parser@^1.0.0:
|
|||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-1.0.0.tgz#ddcc864ae708e60a7a6dd36daea00172fa8d9272"
|
||||
|
||||
vscode-css-languageservice@^3.0.7:
|
||||
version "3.0.7"
|
||||
resolved "https://registry.yarnpkg.com/vscode-css-languageservice/-/vscode-css-languageservice-3.0.7.tgz#ca53f94db020e4e6c7059963fed8dc256593decc"
|
||||
vscode-css-languageservice@^3.0.9-next.1:
|
||||
version "3.0.9-next.1"
|
||||
resolved "https://registry.yarnpkg.com/vscode-css-languageservice/-/vscode-css-languageservice-3.0.9-next.1.tgz#92319b641a7624e84950aef2c55e5b4db001ff9a"
|
||||
dependencies:
|
||||
vscode-languageserver-types "^3.6.0-next.1"
|
||||
vscode-nls "^2.0.1"
|
||||
vscode-languageserver-types "^3.6.1"
|
||||
vscode-nls "^3.2.1"
|
||||
|
||||
vscode-emmet-helper@^1.2.0:
|
||||
version "1.2.0"
|
||||
|
@ -33,31 +33,35 @@ vscode-emmet-helper@^1.2.0:
|
|||
jsonc-parser "^1.0.0"
|
||||
vscode-languageserver-types "^3.6.0-next.1"
|
||||
|
||||
vscode-jsonrpc@^3.6.0-next.1:
|
||||
version "3.6.0-next.1"
|
||||
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-3.6.0-next.1.tgz#3cb463dffe5842d6aec16718ca9252708cd6aabe"
|
||||
vscode-jsonrpc@^3.6.0:
|
||||
version "3.6.0"
|
||||
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-3.6.0.tgz#848d56995d5168950d84feb5d9c237ae5c6a02d4"
|
||||
|
||||
vscode-languageserver-protocol@^3.6.0-next.5:
|
||||
version "3.6.0-next.5"
|
||||
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.6.0-next.5.tgz#ed2ec2db759826f753c0a13977dfb2bedc4d31b3"
|
||||
vscode-languageserver-protocol@^3.6.0:
|
||||
version "3.6.0"
|
||||
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.6.0.tgz#579642cdcccf74b0cd771c33daa3239acb40d040"
|
||||
dependencies:
|
||||
vscode-jsonrpc "^3.6.0-next.1"
|
||||
vscode-languageserver-types "^3.6.0-next.1"
|
||||
vscode-jsonrpc "^3.6.0"
|
||||
vscode-languageserver-types "^3.6.0"
|
||||
|
||||
vscode-languageserver-types@^3.6.0, vscode-languageserver-types@^3.6.1:
|
||||
version "3.6.1"
|
||||
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.6.1.tgz#4bc06a48dff653495f12f94b8b1e228988a1748d"
|
||||
|
||||
vscode-languageserver-types@^3.6.0-next.1:
|
||||
version "3.6.0-next.1"
|
||||
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.6.0-next.1.tgz#98e488d3f87b666b4ee1a3d89f0023e246d358f3"
|
||||
|
||||
vscode-languageserver@4.0.0-next.4:
|
||||
version "4.0.0-next.4"
|
||||
resolved "https://registry.yarnpkg.com/vscode-languageserver/-/vscode-languageserver-4.0.0-next.4.tgz#162440b15bedaab07e1676f046e4d9b8578b3d92"
|
||||
vscode-languageserver@^4.0.0:
|
||||
version "4.0.0"
|
||||
resolved "https://registry.yarnpkg.com/vscode-languageserver/-/vscode-languageserver-4.0.0.tgz#8b792f0d6d10acfe363d02371ed4ce53d08af88a"
|
||||
dependencies:
|
||||
vscode-languageserver-protocol "^3.6.0-next.5"
|
||||
vscode-languageserver-protocol "^3.6.0"
|
||||
vscode-uri "^1.0.1"
|
||||
|
||||
vscode-nls@^2.0.1:
|
||||
version "2.0.2"
|
||||
resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-2.0.2.tgz#808522380844b8ad153499af5c3b03921aea02da"
|
||||
vscode-nls@^3.2.1:
|
||||
version "3.2.2"
|
||||
resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-3.2.2.tgz#3817eca5b985c2393de325197cf4e15eb2aa5350"
|
||||
|
||||
vscode-uri@^1.0.1:
|
||||
version "1.0.1"
|
||||
|
|
Loading…
Reference in a new issue