Skip to content

Commit

Permalink
Move emmet from html extenstion to emmet extension
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Apr 23, 2018
1 parent 147ca54 commit c314388
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 174 deletions.
2 changes: 1 addition & 1 deletion extensions/css-language-features/client/src/cssMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function activate(context: ExtensionContext) {
let clientOptions: LanguageClientOptions = {
documentSelector,
synchronize: {
configurationSection: ['css', 'scss', 'less', 'emmet']
configurationSection: ['css', 'scss', 'less']
},
initializationOptions: {
}
Expand Down
6 changes: 4 additions & 2 deletions extensions/emmet/src/defaultCompletionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import { Stylesheet } from 'EmmetNode';
import { Node, Stylesheet } from 'EmmetNode';
import { isValidLocationForEmmetAbbreviation } from './abbreviationActions';
import { getEmmetHelper, getMappingForIncludedLanguages, parsePartialStylesheet, getEmmetConfiguration, getEmmetMode, isStyleSheet, parseDocument, } from './util';

Expand Down Expand Up @@ -34,7 +34,7 @@ export class DefaultCompletionItemProvider implements vscode.CompletionItemProvi
}

let validateLocation = false;
let rootNode: Stylesheet | undefined = undefined;
let rootNode: Node | undefined = undefined;

if (context.triggerKind !== vscode.CompletionTriggerKind.TriggerForIncompleteCompletions) {
validateLocation = syntax === 'html' || syntax === 'jsx' || syntax === 'xml' || isStyleSheet(document.languageId);
Expand All @@ -45,6 +45,8 @@ export class DefaultCompletionItemProvider implements vscode.CompletionItemProvi
if (!rootNode) {
return;
}
} else if (document.languageId === 'html') {
rootNode = parseDocument(document, false);
}
}

Expand Down
3 changes: 1 addition & 2 deletions extensions/emmet/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ 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'];

function registerCompletionProviders(context: vscode.ExtensionContext) {
let completionProvider = new DefaultCompletionItemProvider();
Expand Down Expand Up @@ -170,7 +169,7 @@ function registerCompletionProviders(context: vscode.ExtensionContext) {
});

Object.keys(LANGUAGE_MODES).forEach(language => {
if (languagesToSkipCompletionProviders.indexOf(language) === -1 && !languageMappingForCompletionProviders.has(language)) {
if (!languageMappingForCompletionProviders.has(language)) {
const provider = vscode.languages.registerCompletionItemProvider(language, completionProvider, ...LANGUAGE_MODES[language]);
context.subscriptions.push(provider);

Expand Down
1 change: 1 addition & 0 deletions extensions/emmet/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const emmetModes = ['html', 'pug', 'slim', 'haml', 'xml', 'xsl', 'jsx', 'css', '
// For other languages, users will have to use `emmet.includeLanguages` or
// language specific extensions can provide emmet completion support
export const MAPPED_MODES: Object = {
'handlebars': 'html',
'php': 'html'
};

Expand Down
2 changes: 1 addition & 1 deletion extensions/html-language-features/client/src/htmlMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function activate(context: ExtensionContext) {
let clientOptions: LanguageClientOptions = {
documentSelector,
synchronize: {
configurationSection: ['html', 'css', 'javascript', 'emmet'], // the settings to synchronize
configurationSection: ['html', 'css', 'javascript'], // the settings to synchronize
},
initializationOptions: {
embeddedLanguages
Expand Down
1 change: 0 additions & 1 deletion extensions/html-language-features/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
},
"dependencies": {
"vscode-css-languageservice": "^3.0.9-next.10",
"vscode-emmet-helper": "1.2.6",
"vscode-html-languageservice": "^2.1.3-next.3",
"vscode-languageserver": "^4.0.0",
"vscode-languageserver-protocol-foldingprovider": "^2.0.0-next.2",
Expand Down
52 changes: 4 additions & 48 deletions extensions/html-language-features/server/src/htmlServerMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
import {
createConnection, IConnection, TextDocuments, InitializeParams, InitializeResult, RequestType,
DocumentRangeFormattingRequest, Disposable, DocumentSelector, TextDocumentPositionParams, ServerCapabilities,
Position, CompletionTriggerKind, ConfigurationRequest, ConfigurationParams, DidChangeWorkspaceFoldersNotification,
Position, ConfigurationRequest, ConfigurationParams, DidChangeWorkspaceFoldersNotification,
WorkspaceFolder, DocumentColorRequest, ColorInformation, ColorPresentationRequest
} from 'vscode-languageserver';
import { TextDocument, Diagnostic, DocumentLink, SymbolInformation, CompletionList } from 'vscode-languageserver-types';
import { TextDocument, Diagnostic, DocumentLink, SymbolInformation } from 'vscode-languageserver-types';
import { getLanguageModes, LanguageModes, Settings } from './modes/languageModes';

import { format } from './modes/formatting';
import { pushAll } from './utils/arrays';
import { getDocumentContext } from './utils/documentContext';
import uri from 'vscode-uri';
import { formatError, runSafe, runSafeAsync } from './utils/runner';
import { doComplete as emmetDoComplete, updateExtensionsPath as updateEmmetExtensionsPath, getEmmetCompletionParticipants } from 'vscode-emmet-helper';

import { FoldingRangeRequest, FoldingRangeServerCapabilities } from 'vscode-languageserver-protocol-foldingprovider';
import { getFoldingRanges } from './modes/htmlFolding';
Expand Down Expand Up @@ -78,10 +77,6 @@ function getDocumentSettings(textDocument: TextDocument, needsDocumentSettings:
return Promise.resolve(void 0);
}

let emmetSettings: any = {};
let currentEmmetExtensionsPath: string;
const emmetTriggerCharacters = ['!', '.', '}', ':', '*', '$', ']', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];

// After the server has started the client sends an initialize request. The server receives
// in the passed params the rootPath of the workspace plus the client capabilities
connection.onInitialize((params: InitializeParams): InitializeResult => {
Expand Down Expand Up @@ -127,7 +122,7 @@ connection.onInitialize((params: InitializeParams): InitializeResult => {
let capabilities: ServerCapabilities & FoldingRangeServerCapabilities = {
// Tell the client that the server works in FULL text document sync mode
textDocumentSync: documents.syncKind,
completionProvider: clientSnippetSupport ? { resolveProvider: true, triggerCharacters: [...emmetTriggerCharacters, '.', ':', '<', '"', '=', '/'] } : undefined,
completionProvider: clientSnippetSupport ? { resolveProvider: true, triggerCharacters: ['.', ':', '<', '"', '=', '/'] } : undefined,
hoverProvider: true,
documentHighlightProvider: true,
documentRangeFormattingProvider: false,
Expand Down Expand Up @@ -184,13 +179,6 @@ connection.onDidChangeConfiguration((change) => {
formatterRegistration = null;
}
}

emmetSettings = globalSettings.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 : undefined);
}
});

const pendingValidationRequests: { [uri: string]: NodeJS.Timer } = {};
Expand Down Expand Up @@ -254,8 +242,6 @@ async function validateTextDocument(textDocument: TextDocument) {
}
}

let cachedCompletionList: CompletionList | null;
const hexColorRegex = /^#[\d,a-f,A-F]{1,6}$/;
connection.onCompletion(async (textDocumentPosition, token) => {
return runSafeAsync(async () => {
const document = documents.get(textDocumentPosition.textDocument.uri);
Expand All @@ -265,22 +251,6 @@ connection.onCompletion(async (textDocumentPosition, token) => {
}
const doComplete = mode.doComplete!;

if (cachedCompletionList
&& !cachedCompletionList.isIncomplete
&& (mode.getId() === 'html' || mode.getId() === 'css')
&& textDocumentPosition.context
&& textDocumentPosition.context.triggerKind === CompletionTriggerKind.TriggerForIncompleteCompletions
) {
let result: CompletionList = emmetDoComplete(document, textDocumentPosition.position, mode.getId(), emmetSettings);
if (result && result.items) {
result.items.push(...cachedCompletionList.items);
} else {
result = cachedCompletionList;
cachedCompletionList = null;
}
return result;
}

if (mode.getId() !== 'html') {
/* __GDPR__
"html.embbedded.complete" : {
Expand All @@ -290,22 +260,8 @@ connection.onCompletion(async (textDocumentPosition, token) => {
connection.telemetry.logEvent({ key: 'html.embbedded.complete', value: { languageId: mode.getId() } });
}

cachedCompletionList = null;
const emmetCompletionList = CompletionList.create([], false);

const emmetCompletionParticipant = getEmmetCompletionParticipants(document, textDocumentPosition.position, mode.getId(), emmetSettings, emmetCompletionList);
const completionParticipants = [emmetCompletionParticipant];

let settings = await getDocumentSettings(document, () => doComplete.length > 2);
let result = doComplete(document, textDocumentPosition.position, settings, completionParticipants);
if (emmetCompletionList.isIncomplete) {
emmetCompletionList.items = 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 CompletionList.create([...emmetCompletionList.items, ...result.items], emmetCompletionList.isIncomplete || result.isIncomplete);
}
let result = doComplete(document, textDocumentPosition.position, settings);
return result;

}, null, `Error while computing completions for ${textDocumentPosition.textDocument.uri}`, token);
Expand Down
22 changes: 2 additions & 20 deletions extensions/html-language-features/server/src/modes/cssMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

import { LanguageModelCache, getLanguageModelCache } from '../languageModelCache';
import { TextDocument, Position, Range, CompletionList } from 'vscode-languageserver-types';
import { getCSSLanguageService, Stylesheet, ICompletionParticipant, FoldingRange } from 'vscode-css-languageservice';
import { getCSSLanguageService, Stylesheet, FoldingRange } from 'vscode-css-languageservice';
import { LanguageMode, Workspace } from './languageModes';
import { HTMLDocumentRegions, CSS_STYLE_RULE } from './embeddedSupport';
import { Color } from 'vscode-languageserver';
import { extractAbbreviation } from 'vscode-emmet-helper';

export function getCSSMode(documentRegions: LanguageModelCache<HTMLDocumentRegions>, workspace: Workspace): LanguageMode {
let cssLanguageService = getCSSLanguageService();
Expand All @@ -25,26 +24,9 @@ export function getCSSMode(documentRegions: LanguageModelCache<HTMLDocumentRegio
let embedded = embeddedCSSDocuments.get(document);
return cssLanguageService.doValidation(embedded, cssStylesheets.get(embedded), settings && settings.css);
},
doComplete(document: TextDocument, position: Position, settings = workspace.settings, registeredCompletionParticipants?: ICompletionParticipant[]) {
doComplete(document: TextDocument, position: Position, settings = workspace.settings) {
let embedded = embeddedCSSDocuments.get(document);
const stylesheet = cssStylesheets.get(embedded);

const nonEmmetCompletionParticipants = [];
if (registeredCompletionParticipants) {
// Css Emmet completions in html files are provided no matter where the cursor is inside the embedded css document
// Mimic the same here, until we solve the issue of css language service not able to parse complete embedded documents when there are errors
for (let i = 0; i < registeredCompletionParticipants.length; i++) {
if (typeof (<any>registeredCompletionParticipants[i]).getId === 'function' && (<any>registeredCompletionParticipants[i]).getId() === 'emmet') {
const extractedResults = extractAbbreviation(document, position, { lookAhead: false, syntax: 'css' });
if (extractedResults && extractedResults.abbreviation) {
registeredCompletionParticipants[i].onCssProperty!({ propertyName: extractedResults.abbreviation, range: extractedResults.abbreviationRange });
}
} else {
nonEmmetCompletionParticipants.push(registeredCompletionParticipants[i]);
}
}
}
cssLanguageService.setCompletionParticipants(nonEmmetCompletionParticipants);
return cssLanguageService.doComplete(embedded, position, stylesheet) || CompletionList.create();
},
doHover(document: TextDocument, position: Position) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'use strict';

import { getLanguageModelCache } from '../languageModelCache';
import { LanguageService as HTMLLanguageService, HTMLDocument, DocumentContext, FormattingOptions, HTMLFormatConfiguration, ICompletionParticipant } from 'vscode-html-languageservice';
import { LanguageService as HTMLLanguageService, HTMLDocument, DocumentContext, FormattingOptions, HTMLFormatConfiguration } from 'vscode-html-languageservice';
import { TextDocument, Position, Range, CompletionItem } from 'vscode-languageserver-types';
import { LanguageMode, Workspace } from './languageModes';

Expand All @@ -18,17 +18,14 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService, workspace:
getId() {
return 'html';
},
doComplete(document: TextDocument, position: Position, settings = workspace.settings, completionParticipants?: ICompletionParticipant[]) {
doComplete(document: TextDocument, position: Position, settings = workspace.settings) {
let options = settings && settings.html && settings.html.suggest;
let doAutoComplete = settings && settings.html && settings.html.autoClosingTags;
if (doAutoComplete) {
options.hideAutoCompleteProposals = true;
}
let pathCompletionProposals: CompletionItem[] = [];
let participants = [getPathCompletionParticipant(document, workspace.folders, pathCompletionProposals)];
if (completionParticipants) {
participants.push(...completionParticipants);
}
htmlLanguageService.setCompletionParticipants(participants);

const htmlDocument = htmlDocuments.get(document);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export interface Settings {
css?: any;
html?: any;
javascript?: any;
emmet?: { [key: string]: any };
}

export interface Workspace {
Expand All @@ -35,7 +34,7 @@ export interface Workspace {
export interface LanguageMode {
getId(): string;
doValidation?: (document: TextDocument, settings?: Settings) => Diagnostic[];
doComplete?: (document: TextDocument, position: Position, settings?: Settings, registeredCompletionParticipants?: any[]) => CompletionList;
doComplete?: (document: TextDocument, position: Position, settings?: Settings) => CompletionList;
doResolve?: (document: TextDocument, item: CompletionItem) => CompletionItem;
doHover?: (document: TextDocument, position: Position) => Hover | null;
doSignatureHelp?: (document: TextDocument, position: Position) => SignatureHelp | null;
Expand Down
72 changes: 0 additions & 72 deletions extensions/html-language-features/server/src/test/emmet.test.ts

This file was deleted.

Loading

0 comments on commit c314388

Please sign in to comment.