Skip to content

Commit

Permalink
Revert move of emmet to css extension Fixes microsoft#44840
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Mar 1, 2018
1 parent 02ea61c commit c16869d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 51 deletions.
55 changes: 5 additions & 50 deletions extensions/css/server/src/cssServerMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,24 @@
'use strict';

import {
createConnection, IConnection, TextDocuments, InitializeParams, InitializeResult, ServerCapabilities, CompletionTriggerKind
createConnection, IConnection, TextDocuments, InitializeParams, InitializeResult, ServerCapabilities
} from 'vscode-languageserver';

import { TextDocument, CompletionList } from 'vscode-languageserver-types';
import { TextDocument } 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, ICompletionParticipant } from 'vscode-css-languageservice';
import { getCSSLanguageService, getSCSSLanguageService, getLESSLanguageService, LanguageSettings, LanguageService, Stylesheet } from 'vscode-css-languageservice';
import { getLanguageModelCache } from './languageModelCache';
import { formatError, runSafe } from './utils/errors';
import { doComplete as emmetDoComplete, updateExtensionsPath as updateEmmetExtensionsPath, getEmmetCompletionParticipants } from 'vscode-emmet-helper';
import uri from 'vscode-uri';

export interface Settings {
css: LanguageSettings;
less: LanguageSettings;
scss: LanguageSettings;
emmet: { [key: string]: any };
}

// Create a connection for the server.
Expand Down Expand Up @@ -54,9 +52,6 @@ connection.onShutdown(() => {

let scopedSettingsSupport = false;
let workspaceFolders: WorkspaceFolder[] | undefined;
let emmetSettings = {};
let currentEmmetExtensionsPath: string;
const emmetTriggerCharacters = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];

// After the server has started the client sends an initilize request. The server receives
// in the passed params the rootPath of the workspace plus the client capabilities.
Expand All @@ -82,7 +77,7 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
let capabilities: ServerCapabilities & CPServerCapabilities = {
// Tell the client that the server works in FULL text document sync mode
textDocumentSync: documents.syncKind,
completionProvider: snippetSupport ? { resolveProvider: false, triggerCharacters: emmetTriggerCharacters } : undefined,
completionProvider: snippetSupport ? { resolveProvider: false } : undefined,
hoverProvider: true,
documentSymbolProvider: true,
referencesProvider: true,
Expand Down Expand Up @@ -141,13 +136,6 @@ function updateConfiguration(settings: Settings) {
documentSettings = {};
// Revalidate any open text documents
documents.all().forEach(triggerValidation);

emmetSettings = settings.emmet;
if (currentEmmetExtensionsPath !== emmetSettings['extensionsPath']) {
currentEmmetExtensionsPath = emmetSettings['extensionsPath'];
const workspaceUri = (workspaceFolders && workspaceFolders.length === 1) ? uri.parse(workspaceFolders[0].uri) : null;
updateEmmetExtensionsPath(currentEmmetExtensionsPath, workspaceUri ? workspaceUri.fsPath : null);
}
}

let pendingValidationRequests: { [uri: string]: NodeJS.Timer } = {};
Expand Down Expand Up @@ -193,43 +181,10 @@ function validateTextDocument(textDocument: TextDocument): void {
});
}

let cachedCompletionList: CompletionList;
const hexColorRegex = /^#[\d,a-f,A-F]{1,6}$/;
connection.onCompletion(textDocumentPosition => {
return runSafe(() => {
let document = documents.get(textDocumentPosition.textDocument.uri);
if (cachedCompletionList
&& !cachedCompletionList.isIncomplete
&& textDocumentPosition.context
&& textDocumentPosition.context.triggerKind === CompletionTriggerKind.TriggerForIncompleteCompletions
) {
let result: CompletionList = emmetDoComplete(document, textDocumentPosition.position, document.languageId, emmetSettings);
if (result && result.items) {
result.items.push(...cachedCompletionList.items);
} else {
result = cachedCompletionList;
cachedCompletionList = null;
}
return result;
}

cachedCompletionList = null;
let emmetCompletionList: CompletionList = {
isIncomplete: false,
items: []
};
const emmetCompletionParticipant: ICompletionParticipant = getEmmetCompletionParticipants(document, textDocumentPosition.position, document.languageId, emmetSettings, emmetCompletionList);
getLanguageService(document).setCompletionParticipants([emmetCompletionParticipant]);

const result = getLanguageService(document).doComplete(document, textDocumentPosition.position, stylesheets.get(document))!; /* TODO: remove ! once LS has null annotations */
if (emmetCompletionList && emmetCompletionList.items) {
cachedCompletionList = result;
if (emmetCompletionList.items.length && hexColorRegex.test(emmetCompletionList.items[0].label) && result.items.some(x => x.label === emmetCompletionList.items[0].label)) {
emmetCompletionList.items.shift();
}
return { isIncomplete: emmetCompletionList.isIncomplete || result.isIncomplete, items: [...emmetCompletionList.items, ...result.items] };
}
return result;
return getLanguageService(document).doComplete(document, textDocumentPosition.position, stylesheets.get(document))!; /* TODO: remove ! once LS has null annotations */
}, null, `Error while computing completions for ${textDocumentPosition.textDocument.uri}`);
});

Expand Down
2 changes: 1 addition & 1 deletion extensions/emmet/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function activate(context: vscode.ExtensionContext) {
*/
const languageMappingForCompletionProviders: Map<string, string> = new Map<string, string>();
const completionProvidersMapping: Map<string, vscode.Disposable> = new Map<string, vscode.Disposable>();
const languagesToSkipCompletionProviders = ['html', 'css', 'scss', 'less'];
const languagesToSkipCompletionProviders = ['html'];

function registerCompletionProviders(context: vscode.ExtensionContext) {
let completionProvider = new DefaultCompletionItemProvider();
Expand Down

0 comments on commit c16869d

Please sign in to comment.