提交 ac60143a 编写于 作者: R Ramya Achutha Rao

Honor emmet.extensionsPath setting for variables and profile

上级 91008076
......@@ -57,13 +57,7 @@
"default": "\n"
}
},
"default":{
"lang": "en",
"locale": "en-US",
"charset": "UTF-8",
"indentation": "\t",
"newline": "\n"
},
"default":{},
"description": "Variables to be used in emmet snippets"
}
}
......
......@@ -10,7 +10,7 @@ import parseStylesheet from '@emmetio/css-parser';
import parse from '@emmetio/html-matcher';
import Node from '@emmetio/node';
import { getSyntax, getProfile, isStyleSheet, getNode, getInnerRange } from './util';
import { getSyntax, getProfile, getVariables, isStyleSheet, getNode, getInnerRange } from './util';
import { DocumentStreamReader } from './bufferStream';
const field = (index, placeholder) => `\${${index}${placeholder ? ':' + placeholder : ''}}`;
......@@ -147,7 +147,7 @@ function getExpandOptions(syntax: string, textToReplace?: string) {
syntax: syntax,
profile: getProfile(syntax),
addons: syntax === 'jsx' ? { 'jsx': true } : null,
variables: vscode.workspace.getConfiguration('emmet')['variables'],
variables: getVariables(),
text: textToReplace ? textToReplace : ''
};
}
\ No newline at end of file
......@@ -15,6 +15,7 @@ import { mergeLines } from './mergeLines';
import { toggleComment } from './toggleComment';
import { fetchEditPoint } from './editPoint';
import { fetchSelectItem } from './selectItem';
import { updateExtensionsPath } from './util';
const LANGUAGE_MODES: Object = {
'html': ['!', '.', '}'],
......@@ -109,6 +110,10 @@ export function activate(context: vscode.ExtensionContext) {
fetchSelectItem('prev');
}));
updateExtensionsPath();
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(() => {
updateExtensionsPath();
}));
}
export function deactivate() {
......
......@@ -7,7 +7,12 @@ import * as vscode from 'vscode';
import parse from '@emmetio/html-matcher';
import Node from '@emmetio/node';
import { DocumentStreamReader } from './bufferStream';
import * as path from 'path';
import * as fs from 'fs';
let variablesFromFile = {};
let profilesFromFile = {};
let emmetExtensionsPath = '';
export function validate(allowStylesheet: boolean = true): boolean {
let editor = vscode.window.activeTextEditor;
if (!editor) {
......@@ -36,8 +41,10 @@ export function isStyleSheet(syntax): boolean {
}
export function getProfile(syntax: string): any {
let config = vscode.workspace.getConfiguration('emmet')['syntaxProfiles'] || {};
let options = config[syntax];
let profilesFromSettings = vscode.workspace.getConfiguration('emmet')['syntaxProfiles'] || {};
let profilesConfig = Object.assign({}, profilesFromFile, profilesFromSettings);
let options = profilesConfig[syntax];
if (!options || typeof options === 'string') {
if (options === 'xhtml') {
return {
......@@ -84,6 +91,46 @@ export function getProfile(syntax: string): any {
return newOptions;
}
export function getVariables(): any {
let variablesFromSettings = vscode.workspace.getConfiguration('emmet')['variables'];
return Object.assign({}, variablesFromFile, variablesFromSettings);
}
export function updateExtensionsPath() {
let currentEmmetExtensionsPath = vscode.workspace.getConfiguration('emmet')['extensionsPath'];
if (emmetExtensionsPath !== currentEmmetExtensionsPath) {
emmetExtensionsPath = currentEmmetExtensionsPath;
if (emmetExtensionsPath && emmetExtensionsPath.trim()) {
let dirPath = path.isAbsolute(emmetExtensionsPath) ? emmetExtensionsPath : path.join(vscode.workspace.rootPath, emmetExtensionsPath);
let snippetsPath = path.join(dirPath, 'snippets.json');
let profilesPath = path.join(dirPath, 'syntaxProfiles.json');
if (dirExists(dirPath)) {
fs.readFile(snippetsPath, (err, snippetsData) => {
if (err) {
return;
}
try {
let snippetsJson = JSON.parse(snippetsData.toString());
variablesFromFile = snippetsJson['variables'];
} catch (e) {
}
});
fs.readFile(profilesPath, (err, profilesData) => {
if (err) {
return;
}
try {
profilesFromFile = JSON.parse(profilesData.toString());
} catch (e) {
}
});
}
}
}
}
export function getOpenCloseRange(document: vscode.TextDocument, position: vscode.Position): [vscode.Range, vscode.Range] {
let rootNode: Node = parse(new DocumentStreamReader(document));
let nodeToUpdate = getNode(rootNode, position);
......@@ -259,4 +306,13 @@ export function sameNodes(node1: Node, node2: Node): boolean {
return false;
}
return (<vscode.Position>node1.start).isEqual(node2.start) && (<vscode.Position>node1.end).isEqual(node2.end);
}
\ No newline at end of file
}
function dirExists(dirPath: string): boolean {
try {
return fs.statSync(dirPath).isDirectory();
} catch (e) {
return false;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册