Skip to content

Commit

Permalink
Merge branch 'master' into spdlog
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomoreno committed Dec 4, 2017
2 parents 2462b84 + 0c8542b commit 83c6d5a
Show file tree
Hide file tree
Showing 741 changed files with 9,847 additions and 2,871 deletions.
6 changes: 6 additions & 0 deletions .github/commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
action: 'close',
comment: "Please ask your question on [StackOverflow](https://aka.ms/vscodestackoverflow). We have a great community over [there](https://aka.ms/vscodestackoverflow). They have already answered thousands of questions and are happy to answer yours as well. See also our [issue reporting](https://aka.ms/vscodeissuereporting) guidelines.\n\nHappy Coding!"
},
{
type: 'label',
name: '*dev-question',
action: 'close',
comment: "We have a great developer community [over on slack](https://aka.ms/vscode-dev-community) where extension authors help each other. This is a great place for you to ask questions and find support.\n\nHappy Coding!"
},
{
type: 'label',
name: '*extension-candidate',
Expand Down
5 changes: 2 additions & 3 deletions build/gulpfile.vscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ const nodeModules = ['electron', 'original-fs']
// Build

const builtInExtensions = [
{ name: 'ms-vscode.node-debug', version: '1.19.5' },
{ name: 'ms-vscode.node-debug2', version: '1.19.0' }
{ name: 'ms-vscode.node-debug', version: '1.19.6' },
{ name: 'ms-vscode.node-debug2', version: '1.19.1' }
];

const excludedExtensions = [
Expand Down Expand Up @@ -138,7 +138,6 @@ const config = {
role: 'Editor',
ostypes: ["TEXT", "utxt", "TUTX", "****"],
extensions: ["ascx", "asp", "aspx", "bash", "bash_login", "bash_logout", "bash_profile", "bashrc", "bat", "bowerrc", "c", "cc", "clj", "cljs", "cljx", "clojure", "cmd", "code-workspace", "coffee", "config", "cpp", "cs", "cshtml", "csproj", "css", "csx", "ctp", "cxx", "dockerfile", "dot", "dtd", "editorconfig", "edn", "eyaml", "eyml", "fs", "fsi", "fsscript", "fsx", "gemspec", "gitattributes", "gitconfig", "gitignore", "go", "h", "handlebars", "hbs", "hh", "hpp", "htm", "html", "hxx", "ini", "jade", "jav", "java", "js", "jscsrc", "jshintrc", "jshtm", "json", "jsp", "less", "lua", "m", "makefile", "markdown", "md", "mdoc", "mdown", "mdtext", "mdtxt", "mdwn", "mkd", "mkdn", "ml", "mli", "php", "phtml", "pl", "pl6", "pm", "pm6", "pod", "pp", "profile", "properties", "ps1", "psd1", "psgi", "psm1", "py", "r", "rb", "rhistory", "rprofile", "rs", "rt", "scss", "sh", "shtml", "sql", "svg", "svgz", "t", "ts", "txt", "vb", "wxi", "wxl", "wxs", "xaml", "xcodeproj", "xcworkspace", "xml", "yaml", "yml", "zlogin", "zlogout", "zprofile", "zsh", "zshenv", "zshrc"],
utis: ['public.source-code'],
iconFile: 'resources/darwin/code_file.icns'
}],
darwinBundleURLTypes: [{
Expand Down
4 changes: 4 additions & 0 deletions extensions/bat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"language": "bat",
"scopeName": "source.batchfile",
"path": "./syntaxes/batchfile.tmLanguage.json"
}],
"snippets": [{
"language": "bat",
"path": "./snippets/batchfile.snippets.json"
}]
}
}
16 changes: 16 additions & 0 deletions extensions/bat/snippets/batchfile.snippets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"Region Start": {
"prefix": "#region",
"body": [
"::#region"
],
"description": "Folding Region Start"
},
"Region End": {
"prefix": "#endregion",
"body": [
"::#endregion"
],
"description": "Folding Region End"
}
}
29 changes: 27 additions & 2 deletions extensions/css/client/src/cssMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import * as path from 'path';

import { languages, window, commands, ExtensionContext, TextDocument, ColorInformation, ColorPresentation, Color } from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, TextEdit } from 'vscode-languageclient';
import { languages, window, commands, ExtensionContext, TextDocument, ColorInformation, ColorPresentation, Color, Range, Position, CompletionItem, CompletionItemKind, TextEdit, SnippetString } from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient';

import { ConfigurationFeature } from 'vscode-languageclient/lib/configuration.proposed';
import { DocumentColorRequest, DocumentColorParams, ColorPresentationRequest, ColorPresentationParams } from 'vscode-languageserver-protocol/lib/protocol.colorProvider.proposed';
Expand Down Expand Up @@ -104,6 +104,31 @@ export function activate(context: ExtensionContext) {
indentationRules: indentationRules
});

const regionCompletionRegExpr = /^(\s*)(\/(\*\s*(#\w*)?)?)?/;
languages.registerCompletionItemProvider(documentSelector, {
provideCompletionItems(doc, pos) {
let lineUntilPos = doc.getText(new Range(new Position(pos.line, 0), pos));
let match = lineUntilPos.match(regionCompletionRegExpr);
if (match) {
let range = new Range(new Position(pos.line, match[1].length), pos);
let beginProposal = new CompletionItem('#region', CompletionItemKind.Snippet);
beginProposal.range = range; TextEdit.replace(range, '/* #region */');
beginProposal.insertText = new SnippetString('/* #region $1*/');
beginProposal.documentation = localize('folding.start', 'Folding Region Start');
beginProposal.filterText = match[2];
beginProposal.sortText = 'za';
let endProposal = new CompletionItem('#endregion', CompletionItemKind.Snippet);
endProposal.range = range;
endProposal.insertText = '/* #endregion */';
endProposal.documentation = localize('folding.end', 'Folding Region End');
endProposal.sortText = 'zb';
endProposal.filterText = match[2];
return [beginProposal, endProposal];
}
return null;
}
});

commands.registerCommand('_css.applyCodeAction', applyCodeAction);

function applyCodeAction(uri: string, documentVersion: number, edits: TextEdit[]) {
Expand Down
2 changes: 1 addition & 1 deletion extensions/emmet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
"@emmetio/html-matcher": "^0.3.1",
"@emmetio/css-parser": "ramya-rao-a/css-parser#vscode",
"@emmetio/math-expression": "^0.1.1",
"vscode-emmet-helper": "^1.1.18",
"vscode-emmet-helper": "^1.1.19",
"vscode-languageserver-types": "^3.0.3",
"image-size": "^0.5.2",
"vscode-nls": "2.0.2"
Expand Down
80 changes: 71 additions & 9 deletions extensions/emmet/src/abbreviationActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
args = args || {};
if (!args['language']) {
args['language'] = vscode.window.activeTextEditor.document.languageId;
} else {
const excludedLanguages = vscode.workspace.getConfiguration('emmet')['excludeLanguages'] ? vscode.workspace.getConfiguration('emmet')['excludeLanguages'] : [];
if (excludedLanguages.indexOf(vscode.window.activeTextEditor.document.languageId) > -1) {
return fallbackTab();
}
}
const syntax = getSyntaxFromArgs(args);
if (!syntax) {
Expand Down Expand Up @@ -176,7 +181,7 @@ export function expandEmmetAbbreviation(args: any): Thenable<boolean | undefined
}

let currentNode = getNode(rootNode, position, true);
if (!isValidLocationForEmmetAbbreviation(currentNode, syntax, position)) {
if (!isValidLocationForEmmetAbbreviation(editor.document, currentNode, syntax, position, rangeToReplace)) {
return;
}

Expand Down Expand Up @@ -205,11 +210,13 @@ function fallbackTab(): Thenable<boolean | undefined> {
/**
* Checks if given position is a valid location to expand emmet abbreviation.
* Works only on html and css/less/scss syntax
* @param document current Text Document
* @param currentNode parsed node at given position
* @param syntax syntax of the abbreviation
* @param position position to validate
* @param abbreviationRange The range of the abbreviation for which given position is being validated
*/
export function isValidLocationForEmmetAbbreviation(currentNode: Node | null, syntax: string, position: vscode.Position): boolean {
export function isValidLocationForEmmetAbbreviation(document: vscode.TextDocument, currentNode: Node | null, syntax: string, position: vscode.Position, abbreviationRange: vscode.Range): boolean {
// Continue validation only if the file was parse-able and the currentNode has been found
if (!currentNode) {
return true;
Expand Down Expand Up @@ -242,13 +249,64 @@ export function isValidLocationForEmmetAbbreviation(currentNode: Node | null, sy
return false;
}

const startAngle = '<';
const endAngle = '>';
const escape = '\\';
const currentHtmlNode = <HtmlNode>currentNode;
if (currentHtmlNode.close) {
const innerRange = getInnerRange(currentHtmlNode);
return !!innerRange && innerRange.contains(position);
const innerRange = getInnerRange(currentHtmlNode);

// Fix for https://github.com/Microsoft/vscode/issues/28829
if (!innerRange || !innerRange.contains(position)) {
return false;
}

// Fix for https://github.com/Microsoft/vscode/issues/35128
// Find the position up till where we will backtrack looking for unescaped < or >
// to decide if current position is valid for emmet expansion
let start = innerRange.start;
let lastChildBeforePosition = currentHtmlNode.firstChild;
while (lastChildBeforePosition) {
if (lastChildBeforePosition.end.isAfter(position)) {
break;
}
start = lastChildBeforePosition.end;
lastChildBeforePosition = lastChildBeforePosition.nextSibling;
}
let textToBackTrack = document.getText(new vscode.Range(start, abbreviationRange.start));

return false;
// Worse case scenario is when cursor is inside a big chunk of text which needs to backtracked
// Backtrack only 500 offsets to ensure we dont waste time doing this
if (textToBackTrack.length > 500) {
textToBackTrack = textToBackTrack.substr(textToBackTrack.length - 500);
}

let valid = true;
let foundSpace = false; // If < is found before finding whitespace, then its valid abbreviation. Eg: <div|
let i = textToBackTrack.length - 1;
while (i >= 0) {
const char = textToBackTrack[i];
i--;
if (!foundSpace && /\s/.test(char)) {
foundSpace = true;
continue;
}
if (char !== startAngle && char !== endAngle) {
continue;
}
if (i >= 0 && textToBackTrack[i] === escape) {
i--;
continue;
}
if (char === endAngle) {
break;
}
if (char === startAngle) {
valid = !foundSpace;
break;
}
}

return valid;
}

/**
Expand Down Expand Up @@ -343,9 +401,13 @@ function expandAbbr(input: ExpandAbbreviationInput): string | undefined {

function getSyntaxFromArgs(args: Object): string | undefined {
const mappedModes = getMappingForIncludedLanguages();
let language: string = args['language'];
let parentMode: string = args['parentMode'];
let excludedLanguages = vscode.workspace.getConfiguration('emmet')['excludeLanguages'] ? vscode.workspace.getConfiguration('emmet')['excludeLanguages'] : [];
const language: string = args['language'];
const parentMode: string = args['parentMode'];
const excludedLanguages = vscode.workspace.getConfiguration('emmet')['excludeLanguages'] ? vscode.workspace.getConfiguration('emmet')['excludeLanguages'] : [];
if (excludedLanguages.indexOf(language) > -1) {
return;
}

let syntax = getEmmetMode((mappedModes[language] ? mappedModes[language] : language), excludedLanguages);
if (!syntax) {
syntax = getEmmetMode((mappedModes[parentMode] ? mappedModes[parentMode] : parentMode), excludedLanguages);
Expand Down
71 changes: 37 additions & 34 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 { HtmlNode } from 'EmmetNode';
import { HtmlNode, Node } from 'EmmetNode';
import { isValidLocationForEmmetAbbreviation } from './abbreviationActions';
import { getEmmetHelper, getNode, getInnerRange, getMappingForIncludedLanguages, parseDocument, getEmmetConfiguration, getEmmetMode, isStyleSheet } from './util';

Expand All @@ -13,17 +13,37 @@ const allowedMimeTypesInScriptTag = ['text/html', 'text/plain', 'text/x-template
export class DefaultCompletionItemProvider implements vscode.CompletionItemProvider {

public provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Thenable<vscode.CompletionList | undefined> | undefined {
const mappedLanguages = getMappingForIncludedLanguages();
const emmetConfig = vscode.workspace.getConfiguration('emmet');
const excludedLanguages = emmetConfig['excludeLanguages'] ? emmetConfig['excludeLanguages'] : [];
if (excludedLanguages.indexOf(document.languageId) > -1) {
return;
}

let isSyntaxMapped = mappedLanguages[document.languageId] ? true : false;
let excludedLanguages = emmetConfig['excludeLanguages'] ? emmetConfig['excludeLanguages'] : [];
const mappedLanguages = getMappingForIncludedLanguages();
const isSyntaxMapped = mappedLanguages[document.languageId] ? true : false;
let syntax = getEmmetMode((isSyntaxMapped ? mappedLanguages[document.languageId] : document.languageId), excludedLanguages);

const helper = getEmmetHelper();
const extractAbbreviationResults = helper.extractAbbreviation(document, position);
if (!extractAbbreviationResults) {
return;
}

// If document can be html/css parsed, validate syntax and location
if (document.languageId === 'html' || isStyleSheet(document.languageId)) {
// Document can be html/css parsed
// Use syntaxHelper to parse file, validate location and update sytnax if needed
syntax = this.syntaxHelper(syntax, document, position);
const rootNode = parseDocument(document, false);
if (!rootNode) {
return;
}

// Use syntaxHelper to update sytnax if needed
const currentNode = getNode(rootNode, position, true);
syntax = this.syntaxHelper(syntax, currentNode, position);

// Validate location
if (!syntax || !isValidLocationForEmmetAbbreviation(document, currentNode, syntax, position, extractAbbreviationResults.abbreviationRange)) {
return;
}
}

if (!syntax
Expand All @@ -32,23 +52,19 @@ export class DefaultCompletionItemProvider implements vscode.CompletionItemProvi
return;
}

const helper = getEmmetHelper();
let noiseCheckPromise: Thenable<any> = Promise.resolve();

// Fix for https://github.com/Microsoft/vscode/issues/32647
// Check for document symbols in js/ts/jsx/tsx and avoid triggering emmet for abbreviations of the form symbolName.sometext
// Presence of > or * or + in the abbreviation denotes valid abbreviation that should trigger emmet
if (!isStyleSheet(syntax) && (document.languageId === 'javascript' || document.languageId === 'javascriptreact' || document.languageId === 'typescript' || document.languageId === 'typescriptreact')) {
let extractAbbreviationResults = helper.extractAbbreviation(document, position);
if (extractAbbreviationResults) {
let abbreviation: string = extractAbbreviationResults.abbreviation;
if (abbreviation.startsWith('this.')) {
noiseCheckPromise = Promise.resolve(true);
} else {
noiseCheckPromise = vscode.commands.executeCommand<vscode.SymbolInformation[]>('vscode.executeDocumentSymbolProvider', document.uri).then((symbols: vscode.SymbolInformation[] | undefined) => {
return symbols && symbols.find(x => abbreviation === x.name || (abbreviation.startsWith(x.name + '.') && !/>|\*|\+/.test(abbreviation)));
});
}
let abbreviation: string = extractAbbreviationResults.abbreviation;
if (abbreviation.startsWith('this.')) {
noiseCheckPromise = Promise.resolve(true);
} else {
noiseCheckPromise = vscode.commands.executeCommand<vscode.SymbolInformation[]>('vscode.executeDocumentSymbolProvider', document.uri).then((symbols: vscode.SymbolInformation[] | undefined) => {
return symbols && symbols.find(x => abbreviation === x.name || (abbreviation.startsWith(x.name + '.') && !/>|\*|\+/.test(abbreviation)));
});
}
}

Expand Down Expand Up @@ -85,21 +101,11 @@ export class DefaultCompletionItemProvider implements vscode.CompletionItemProvi
/**
* Parses given document to check whether given position is valid for emmet abbreviation and returns appropriate syntax
* @param syntax string language mode of current document
* @param document vscode.Textdocument
* @param currentNode node in the document that contains the position
* @param position vscode.Position position of the abbreviation that needs to be expanded
*/
private syntaxHelper(syntax: string | undefined, document: vscode.TextDocument, position: vscode.Position): string | undefined {
if (!syntax) {
return syntax;
}
let rootNode = parseDocument(document, false);
if (!rootNode) {
return;
}

let currentNode = getNode(rootNode, position, true);

if (!isStyleSheet(syntax)) {
private syntaxHelper(syntax: string | undefined, currentNode: Node | null, position: vscode.Position): string | undefined {
if (syntax && !isStyleSheet(syntax)) {
const currentHtmlNode = <HtmlNode>currentNode;
if (currentHtmlNode && currentHtmlNode.close) {
const innerRange = getInnerRange(currentHtmlNode);
Expand All @@ -118,9 +124,6 @@ export class DefaultCompletionItemProvider implements vscode.CompletionItemProvi
}
}

if (!isValidLocationForEmmetAbbreviation(currentNode, syntax, position)) {
return;
}
return syntax;
}

Expand Down
Loading

0 comments on commit 83c6d5a

Please sign in to comment.