Skip to content

Commit

Permalink
Get emmet completions from html,css extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Feb 12, 2018
1 parent ef42990 commit 5d3362e
Show file tree
Hide file tree
Showing 21 changed files with 266 additions and 97 deletions.
2 changes: 1 addition & 1 deletion extensions/css/client/src/cssMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function activate(context: ExtensionContext) {
let clientOptions: LanguageClientOptions = {
documentSelector,
synchronize: {
configurationSection: ['css', 'scss', 'less']
configurationSection: ['css', 'scss', 'less', 'emmet']
},
initializationOptions: {
}
Expand Down
4 changes: 2 additions & 2 deletions extensions/css/client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"compilerOptions": {
"target": "es5",
"target": "es6",
"module": "commonjs",
"outDir": "./out",
"noUnusedLocals": true,
"lib": [
"es5", "es2015.promise"
"es2016"
],
"strict": true
},
Expand Down
4 changes: 2 additions & 2 deletions extensions/css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -713,10 +713,10 @@
]
},
"dependencies": {
"vscode-languageclient": "^3.5.0",
"vscode-languageclient": "^4.0.0-next.8",
"vscode-nls": "^3.2.1"
},
"devDependencies": {
"@types/node": "7.0.43"
}
}
}
3 changes: 2 additions & 1 deletion extensions/css/server/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"name": "Attach",
"type": "node",
"request": "attach",
"port": 6004,
"port": 6044,
"protocol": "inspector",
"sourceMaps": true,
"outDir": "${workspaceFolder}/out"
},
Expand Down
3 changes: 2 additions & 1 deletion extensions/css/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
"dependencies": {
"vscode-css-languageservice": "^3.0.5",
"vscode-languageserver": "^3.5.0"
"vscode-languageserver": "^4.0.0-next.4",
"vscode-emmet-helper": "1.1.28"
},
"devDependencies": {
"@types/node": "7.0.43"
Expand Down
62 changes: 55 additions & 7 deletions extensions/css/server/src/cssServerMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,30 @@
'use strict';

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

import { TextDocument } from 'vscode-languageserver-types';
import { TextDocument, CompletionList } from 'vscode-languageserver-types';

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

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

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

// Create a connection for the server.
let connection: IConnection = createConnection();

Expand All @@ -49,6 +55,7 @@ connection.onShutdown(() => {
});

let scopedSettingsSupport = false;

// 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.
connection.onInitialize((params: InitializeParams): InitializeResult => {
Expand All @@ -65,7 +72,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 } : undefined,
completionProvider: snippetSupport ? { resolveProvider: false, triggerCharacters: emmetTriggerCharacters } : undefined,
hoverProvider: true,
documentSymbolProvider: true,
referencesProvider: true,
Expand Down Expand Up @@ -124,6 +131,12 @@ function updateConfiguration(settings: Settings) {
documentSettings = {};
// Revalidate any open text documents
documents.all().forEach(triggerValidation);

emmetSettings = settings.emmet;
if (currentEmmetExtensionsPath !== emmetSettings['extensionsPath']) {
currentEmmetExtensionsPath = emmetSettings['extensionsPath'];
updateEmmetExtensionsPath(currentEmmetExtensionsPath);
}
}

let pendingValidationRequests: { [uri: string]: NodeJS.Timer } = {};
Expand Down Expand Up @@ -169,11 +182,46 @@ function validateTextDocument(textDocument: TextDocument): void {
});
}

const hexColorRegex = /^#[\d,a-f,A-F]+$/;
let cachedCompletionList: CompletionList;
connection.onCompletion(textDocumentPosition => {
return runSafe(() => {
let document = documents.get(textDocumentPosition.textDocument.uri);
let stylesheet = stylesheets.get(document);
return getLanguageService(document).doComplete(document, textDocumentPosition.position, stylesheet)!; /* TODO: remove ! once LS has null annotations */
const document = documents.get(textDocumentPosition.textDocument.uri);
const triggerForIncompleteCompletions = textDocumentPosition.context && textDocumentPosition.context.triggerKind === CompletionTriggerKind.TriggerForIncompleteCompletions;
if (triggerForIncompleteCompletions && cachedCompletionList && !cachedCompletionList.isIncomplete) {
let result: CompletionList = emmetDoComplete(document, textDocumentPosition.position, document.languageId, emmetSettings);
if (result && result.items && result.items.length) {
result.items.push(...cachedCompletionList.items);
} else {
result = cachedCompletionList;
cachedCompletionList = null;
}
return result;
}

cachedCompletionList = null;
let emmetCompletionList: CompletionList;
const emmetCompletionParticipant: ICompletionParticipant = {
onCssProperty: (context) => {
if (context && context.propertyName) {
emmetCompletionList = emmetDoComplete(document, textDocumentPosition.position, document.languageId, emmetSettings);
}
},
onCssPropertyValue: (context) => {
if (context && hexColorRegex.test(context.propertyValue)) {
emmetCompletionList = emmetDoComplete(document, textDocumentPosition.position, document.languageId, emmetSettings);
}
}
};
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 && emmetCompletionList.items.length) {
cachedCompletionList = { isIncomplete: result.isIncomplete, items: [...result.items] };
result.items.push(...emmetCompletionList.items);
result.isIncomplete = true;
}
return result;
}, null, `Error while computing completions for ${textDocumentPosition.textDocument.uri}`);
});

Expand Down
44 changes: 32 additions & 12 deletions extensions/css/server/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,57 @@
# yarn lockfile v1


"@emmetio/extract-abbreviation@^0.1.4":
version "0.1.4"
resolved "https://registry.yarnpkg.com/@emmetio/extract-abbreviation/-/extract-abbreviation-0.1.4.tgz#f5be070db97901ecc37e5204f2ace68242cdcefa"

"@types/node@7.0.43":
version "7.0.43"
resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.43.tgz#a187e08495a075f200ca946079c914e1a5fe962c"

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.5:
version "3.0.5"
resolved "https://registry.yarnpkg.com/vscode-css-languageservice/-/vscode-css-languageservice-3.0.5.tgz#8470989c07bbe740db4fa621423e98384d2c342f"
dependencies:
vscode-languageserver-types "3.5.0"
vscode-nls "^2.0.1"

vscode-jsonrpc@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-3.5.0.tgz#87239d9e166b2d7352245b8a813597804c1d63aa"

vscode-languageserver-protocol@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.5.0.tgz#067c5cbe27709795398d119692c97ebba1452209"
vscode-emmet-helper@1.1.28:
version "1.1.28"
resolved "https://registry.yarnpkg.com/vscode-emmet-helper/-/vscode-emmet-helper-1.1.28.tgz#a6633d125a0dc8da3f66e3f2640338ce72e2d650"
dependencies:
vscode-jsonrpc "^3.5.0"
"@emmetio/extract-abbreviation" "^0.1.4"
jsonc-parser "^1.0.0"
vscode-languageserver-types "^3.5.0"

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-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"
dependencies:
vscode-jsonrpc "^3.6.0-next.1"
vscode-languageserver-types "^3.6.0-next.1"

vscode-languageserver-types@3.5.0, vscode-languageserver-types@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.5.0.tgz#e48d79962f0b8e02de955e3f524908e2b19c0374"

vscode-languageserver@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver/-/vscode-languageserver-3.5.0.tgz#d28099bc6ddda8c1dd16b707e454e1b1ddae0dba"
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"
dependencies:
vscode-languageserver-protocol "^3.5.0"
vscode-languageserver-protocol "^3.6.0-next.5"
vscode-uri "^1.0.1"

vscode-nls@^2.0.1:
Expand Down
30 changes: 15 additions & 15 deletions extensions/css/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
version "7.0.43"
resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.43.tgz#a187e08495a075f200ca946079c914e1a5fe962c"

vscode-jsonrpc@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-3.5.0.tgz#87239d9e166b2d7352245b8a813597804c1d63aa"
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-languageclient@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/vscode-languageclient/-/vscode-languageclient-3.5.0.tgz#36d02cc186a8365a4467719a290fb200a9ae490a"
vscode-languageclient@^4.0.0-next.8:
version "4.0.0-next.8"
resolved "https://registry.yarnpkg.com/vscode-languageclient/-/vscode-languageclient-4.0.0-next.8.tgz#eb8eef0bf08399924f8fa520cb0b37071086e7c0"
dependencies:
vscode-languageserver-protocol "^3.5.0"
vscode-languageserver-protocol "^3.6.0-next.5"

vscode-languageserver-protocol@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.5.0.tgz#067c5cbe27709795398d119692c97ebba1452209"
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"
dependencies:
vscode-jsonrpc "^3.5.0"
vscode-languageserver-types "^3.5.0"
vscode-jsonrpc "^3.6.0-next.1"
vscode-languageserver-types "^3.6.0-next.1"

vscode-languageserver-types@^3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.5.0.tgz#e48d79962f0b8e02de955e3f524908e2b19c0374"
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-nls@^3.2.1:
version "3.2.1"
Expand Down
3 changes: 2 additions & 1 deletion extensions/emmet/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +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'];

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

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

Expand Down
1 change: 0 additions & 1 deletion extensions/emmet/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ 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/client/src/htmlMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function activate(context: ExtensionContext) {
let clientOptions: LanguageClientOptions = {
documentSelector,
synchronize: {
configurationSection: ['html', 'css', 'javascript'], // the settings to synchronize
configurationSection: ['html', 'css', 'javascript', 'emmet'], // the settings to synchronize
},
initializationOptions: {
embeddedLanguages
Expand Down
4 changes: 2 additions & 2 deletions extensions/html/client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"compilerOptions": {
"target": "es5",
"target": "es6",
"module": "commonjs",
"outDir": "./out",
"noUnusedLocals": true,
"lib": [
"es5", "es2015.promise"
"es2016"
],
"strict": true
}
Expand Down
14 changes: 8 additions & 6 deletions extensions/html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@
"end": "^\\s*<!--\\s*#endregion\\b\\s*(.*?)-->/"
}
},
"snippets": [{
"language": "html",
"path": "./snippets/html.snippets.json"
}],
"snippets": [
{
"language": "html",
"path": "./snippets/html.snippets.json"
}
],
"configuration": {
"id": "html",
"order": 20,
Expand Down Expand Up @@ -225,10 +227,10 @@
},
"dependencies": {
"vscode-extension-telemetry": "0.0.11",
"vscode-languageclient": "^3.5.0",
"vscode-languageclient": "^4.0.0-next.8",
"vscode-nls": "^3.2.1"
},
"devDependencies": {
"@types/node": "7.0.43"
}
}
}
3 changes: 2 additions & 1 deletion extensions/html/server/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"name": "Attach",
"type": "node",
"request": "attach",
"port": 6004,
"port": 6045,
"protocol": "inspector",
"sourceMaps": true,
"outDir": "${workspaceFolder}/out"
},
Expand Down
6 changes: 4 additions & 2 deletions extensions/html/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
"dependencies": {
"vscode-css-languageservice": "^3.0.5",
"vscode-html-languageservice": "^2.0.15",
"vscode-languageserver": "^3.5.0",
"vscode-languageserver": "^4.0.0-next.4",
"vscode-languageserver-types": "^3.6.0-next.1",
"vscode-nls": "^3.2.1",
"vscode-uri": "^1.0.1"
"vscode-uri": "^1.0.1",
"vscode-emmet-helper": "1.1.28"
},
"devDependencies": {
"@types/mocha": "2.2.33",
Expand Down
Loading

0 comments on commit 5d3362e

Please sign in to comment.