Skip to content

Commit

Permalink
Merge branch 'master' into isidorn/next
Browse files Browse the repository at this point in the history
  • Loading branch information
isidorn committed Aug 3, 2017
2 parents 6a27b2e + c26f8a3 commit 754b68a
Show file tree
Hide file tree
Showing 21 changed files with 205 additions and 100 deletions.
6 changes: 3 additions & 3 deletions extensions/emmet/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion extensions/emmet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
"@emmetio/html-matcher": "^0.3.1",
"@emmetio/css-parser": "^0.3.0",
"@emmetio/math-expression": "^0.1.1",
"vscode-emmet-helper": "^1.0.7",
"vscode-emmet-helper": "^1.0.10",
"vscode-languageserver-types": "^3.0.3",
"image-size": "^0.5.2",
"vscode-nls": "2.0.2"
Expand Down
36 changes: 25 additions & 11 deletions extensions/emmet/src/abbreviationActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { Node, HtmlNode, Rule } from 'EmmetNode';
import { getNode, getInnerRange, getMappingForIncludedLanguages, parseDocument, validate } from './util';
import { getExpandOptions, extractAbbreviation, extractAbbreviationFromText, isStyleSheet, isAbbreviationValid, getEmmetMode, expandAbbreviation } from 'vscode-emmet-helper';

const trimRegex = /[\u00a0]*[\d|#|\-|\*|\u2022]+\.?/;

interface ExpandAbbreviationInput {
syntax: string;
abbreviation: string;
rangeToReplace: vscode.Range;
textToWrap?: string | string[];
textToWrap?: string[];
filters?: string[];
}

Expand All @@ -23,7 +25,7 @@ export function wrapWithAbbreviation(args) {

const editor = vscode.window.activeTextEditor;
const abbreviationPromise = (args && args['abbreviation']) ? Promise.resolve(args['abbreviation']) : vscode.window.showInputBox({ prompt: 'Enter Abbreviation' });
const syntax = getSyntaxFromArgs({ language: editor.document.languageId }) || 'html';
const syntax = getSyntaxFromArgs({ language: editor.document.languageId });

return abbreviationPromise.then(abbreviation => {
if (!abbreviation || !abbreviation.trim() || !isAbbreviationValid(syntax, abbreviation)) { return; }
Expand All @@ -41,7 +43,7 @@ export function wrapWithAbbreviation(args) {
const preceedingWhiteSpace = matches ? matches[1].length : 0;

rangeToReplace = new vscode.Range(rangeToReplace.start.line, rangeToReplace.start.character + preceedingWhiteSpace, rangeToReplace.end.line, rangeToReplace.end.character);
expandAbbrList.push({ syntax, abbreviation, rangeToReplace, textToWrap: '\n\t\$TM_SELECTED_TEXT\n' });
expandAbbrList.push({ syntax, abbreviation, rangeToReplace, textToWrap: ['\n\t\$TM_SELECTED_TEXT\n'] });
});

return expandAbbreviationInRange(editor, expandAbbrList, true);
Expand All @@ -60,17 +62,19 @@ export function wrapIndividualLinesWithAbbreviation(args) {
}

const abbreviationPromise = (args && args['abbreviation']) ? Promise.resolve(args['abbreviation']) : vscode.window.showInputBox({ prompt: 'Enter Abbreviation' });
const syntax = getSyntaxFromArgs({ language: editor.document.languageId }) || 'html';
const syntax = getSyntaxFromArgs({ language: editor.document.languageId });
const lines = editor.document.getText(editor.selection).split('\n').map(x => x.trim());

return abbreviationPromise.then(abbreviation => {
if (!abbreviation || !abbreviation.trim() || !isAbbreviationValid(syntax, abbreviation)) { return; }
return abbreviationPromise.then(inputAbbreviation => {
if (!inputAbbreviation || !inputAbbreviation.trim() || !isAbbreviationValid(syntax, inputAbbreviation)) { return; }

let { abbreviation, filters } = extractAbbreviationFromText(inputAbbreviation);
let input: ExpandAbbreviationInput = {
syntax,
abbreviation,
rangeToReplace: editor.selection,
textToWrap: lines
textToWrap: lines,
filters
};

return expandAbbreviationInRange(editor, [input], true);
Expand Down Expand Up @@ -228,7 +232,13 @@ function expandAbbr(input: ExpandAbbreviationInput): string {
const emmetConfig = vscode.workspace.getConfiguration('emmet');
const expandOptions = getExpandOptions(input.syntax, emmetConfig['syntaxProfiles'], emmetConfig['variables'], input.filters);


if (input.textToWrap) {
if (input.filters && input.filters.indexOf('t') > -1) {
input.textToWrap = input.textToWrap.map(line => {
return line.replace(trimRegex, '').trim();
});
}
expandOptions['text'] = input.textToWrap;

// Below fixes https://github.com/Microsoft/vscode/issues/29898
Expand All @@ -244,7 +254,7 @@ function expandAbbr(input: ExpandAbbreviationInput): string {
let expandedText = expandAbbreviation(input.abbreviation, expandOptions);

// If the expanded text is single line then we dont need the \t we added to $TM_SELECTED_TEXT earlier
if (input.textToWrap && expandedText.indexOf('\n') === -1) {
if (input.textToWrap && input.textToWrap.length === 1 && expandedText.indexOf('\n') === -1) {
expandedText = expandedText.replace(/\s*\$TM_SELECTED_TEXT\s*/, '\$TM_SELECTED_TEXT');
}
return expandedText;
Expand All @@ -268,9 +278,13 @@ function getSyntaxFromArgs(args: any): string {
let parentMode: string = (args && typeof args === 'object') ? args['parentMode'] : undefined;
let excludedLanguages = vscode.workspace.getConfiguration('emmet')['excludeLanguages'] ? vscode.workspace.getConfiguration('emmet')['excludeLanguages'] : [];
let syntax = getEmmetMode((mappedModes[language] ? mappedModes[language] : language), excludedLanguages);
if (syntax) {
return syntax;
if (!syntax) {
syntax = getEmmetMode((mappedModes[parentMode] ? mappedModes[parentMode] : parentMode), excludedLanguages);
}

return getEmmetMode((mappedModes[parentMode] ? mappedModes[parentMode] : parentMode), excludedLanguages);
// Final fallback to html
if (!syntax) {
syntax = getEmmetMode('html', excludedLanguages);
}
return syntax;
}
24 changes: 24 additions & 0 deletions extensions/emmet/src/test/abbreviationAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,30 @@ suite('Tests for Wrap with Abbreviations', () => {
});
});
});

test('Wrap individual lines with abbreviation and trim', () => {
const contents = `
<ul class="nav main">
• lorem ipsum
• lorem ipsum
</ul>
`;
const wrapIndividualLinesExpected = `
<ul class="nav main">
<ul>
<li class="hello1">lorem ipsum</li>
<li class="hello2">lorem ipsum</li>
</ul>
</ul>
`;
return withRandomFileEditor(contents, 'html', (editor, doc) => {
editor.selections = [new Selection(2, 3, 3, 16)];
return wrapIndividualLinesWithAbbreviation({ abbreviation: 'ul>li.hello$*|t' }).then(() => {
assert.equal(editor.document.getText(), wrapIndividualLinesExpected);
return Promise.resolve();
});
});
});
});


Expand Down
31 changes: 10 additions & 21 deletions extensions/markdown/src/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,36 +86,25 @@ export class PreviewSecuritySelector {
) { }

public async showSecutitySelectorForResource(resource: vscode.Uri): Promise<void> {
function markActiveWhen(when: boolean): string {
return when ? '• ' : '';
}

const currentSecurityLevel = this.cspArbiter.getSecurityLevelForResource(resource);
const selection = await vscode.window.showQuickPick<PreviewSecurityPickItem>(
[
{
level: MarkdownPreviewSecurityLevel.Strict,
label: localize(
'preview.showPreviewSecuritySelector.strictTitle',
'Strict. Only load secure content'),
description: '',
detail: currentSecurityLevel === MarkdownPreviewSecurityLevel.Strict
? localize('preview.showPreviewSecuritySelector.currentSelection', 'Current setting')
: ''
label: markActiveWhen(currentSecurityLevel === MarkdownPreviewSecurityLevel.Strict) + localize('strict.title', 'Strict'),
description: localize('strict.description', 'Only load secure content'),
}, {
level: MarkdownPreviewSecurityLevel.AllowInsecureContent,
label: localize(
'preview.showPreviewSecuritySelector.insecureContentTitle',
'Allow loading content over http'),
description: '',
detail: currentSecurityLevel === MarkdownPreviewSecurityLevel.AllowInsecureContent
? localize('preview.showPreviewSecuritySelector.currentSelection', 'Current setting')
: ''
label: markActiveWhen(currentSecurityLevel === MarkdownPreviewSecurityLevel.AllowInsecureContent) + localize('insecureContent.title', 'Allow insecure content'),
description: localize('insecureContent.description', 'Enable loading content over http'),
}, {
level: MarkdownPreviewSecurityLevel.AllowScriptsAndAllContent,
label: localize(
'preview.showPreviewSecuritySelector.scriptsAndAllContent',
'Allow all content and script execution. Not recommended'),
description: '',
detail: currentSecurityLevel === MarkdownPreviewSecurityLevel.AllowScriptsAndAllContent
? localize('preview.showPreviewSecuritySelector.currentSelection', 'Current setting')
: ''
label: markActiveWhen(currentSecurityLevel === MarkdownPreviewSecurityLevel.AllowScriptsAndAllContent) + localize('disable.title', 'Disable'),
description: localize('disable.description', 'Allow all content and script execution. Not recommended'),
},
], {
placeHolder: localize(
Expand Down
26 changes: 16 additions & 10 deletions extensions/php/syntaxes/php.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"information_for_contributors": [
"This file has been converted from https://github.com/atom/language-php/blob/master/grammars/php.cson",
"This file has been converted from https://github.com/roblourens/language-php/blob/vscode_1.15/grammars/php.cson",
"If you want to provide a fix or improvement, please create a pull request against the original repository.",
"Once accepted there, we are happy to receive an update request."
],
"version": "https://github.com/atom/language-php/commit/9cb0db1e4fcb14532e93c873187406e6ba829af4",
"version": "https://github.com/roblourens/language-php/commit/91d50ab5f871ea2d11b4c511dc0b9a972e4ac5ce",
"scopeName": "text.html.php",
"name": "PHP",
"fileTypes": [
Expand Down Expand Up @@ -154,20 +154,23 @@
"class-body": {
"patterns": [
{
"match": "(?xi)\n\\b(use)\\s+\n([a-z_\\x{7f}-\\x{ff}][a-z0-9_\\x{7f}-\\x{ff}]*)\n((?:\\s*,\\s*[a-z_\\x{7f}-\\x{ff}][a-z0-9_\\x{7f}-\\x{ff}]*)*)\n(?=\\s*;)",
"match": "(?xi)\n\\b(use)\\s+\n([a-z_\\x{7f}-\\x{ff}\\\\][a-z0-9_\\x{7f}-\\x{ff}\\\\]*)\n((?:\\s*,\\s*[a-z_\\x{7f}-\\x{ff}\\\\][a-z0-9_\\x{7f}-\\x{ff}\\\\]*)*)\n(?=\\s*;)",
"name": "meta.use.php",
"captures": {
"1": {
"name": "keyword.other.use.php"
},
"2": {
"name": "support.class.php"
"patterns": [
{
"include": "#class-name"
}
]
},
"3": {
"patterns": [
{
"match": "(?i)[a-z_\\x{7f}-\\x{ff}][a-z0-9_\\x{7f}-\\x{ff}]*",
"name": "support.class.php"
"include": "#class-name"
},
{
"match": ",",
Expand All @@ -193,16 +196,19 @@
"name": "meta.use.php",
"patterns": [
{
"match": "(?xi)\n([a-z_\\x{7f}-\\x{ff}][a-z0-9_\\x{7f}-\\x{ff}]*)\n((?:\\s*,\\s*[a-z_\\x{7f}-\\x{ff}][a-z0-9_\\x{7f}-\\x{ff}]*)*)",
"match": "(?xi)\n([a-z_\\x{7f}-\\x{ff}\\\\][a-z0-9_\\x{7f}-\\x{ff}\\\\]*)\n((?:\\s*,\\s*[a-z_\\x{7f}-\\x{ff}\\\\][a-z0-9_\\x{7f}-\\x{ff}\\\\]*)*)",
"captures": {
"1": {
"name": "support.class.php"
"patterns": [
{
"include": "#class-name"
}
]
},
"2": {
"patterns": [
{
"match": "(?i)[a-z_\\x{7f}-\\x{ff}][a-z0-9_\\x{7f}-\\x{ff}]*",
"name": "support.class.php"
"include": "#class-name"
},
{
"match": ",",
Expand Down
16 changes: 10 additions & 6 deletions extensions/typescript/src/typescriptMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,16 +423,20 @@ class LanguageProvider {
}

public syntaxDiagnosticsReceived(file: string, diagnostics: Diagnostic[]): void {
this.syntaxDiagnostics[file] = diagnostics;
if (this._validate) {
this.syntaxDiagnostics[file] = diagnostics;
}
}

public semanticDiagnosticsReceived(file: string, diagnostics: Diagnostic[]): void {
const syntaxMarkers = this.syntaxDiagnostics[file];
if (syntaxMarkers) {
delete this.syntaxDiagnostics[file];
diagnostics = syntaxMarkers.concat(diagnostics);
if (this._validate) {
const syntaxMarkers = this.syntaxDiagnostics[file];
if (syntaxMarkers) {
delete this.syntaxDiagnostics[file];
diagnostics = syntaxMarkers.concat(diagnostics);
}
this.currentDiagnostics.set(this.client.asUrl(file), diagnostics);
}
this.currentDiagnostics.set(this.client.asUrl(file), diagnostics);
}

public configFileDiagnosticsReceived(file: string, diagnostics: Diagnostic[]): void {
Expand Down
4 changes: 2 additions & 2 deletions extensions/typescript/src/typescriptServiceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
this._apiVersion = API.defaultVersion;
this.tracer = new Tracer(this.logger);

this.disposables.push(workspace.onDidChangeConfiguration(() => {
workspace.onDidChangeConfiguration(() => {
const oldConfiguration = this.configuration;
this.configuration = TypeScriptServiceConfiguration.loadFromWorkspace();

Expand All @@ -199,7 +199,7 @@ export default class TypeScriptServiceClient implements ITypescriptServiceClient
this.restartTsServer();
}
}
}));
}, this, this.disposables);
this.telemetryReporter = new TelemetryReporter();
this.disposables.push(this.telemetryReporter);
this.startService();
Expand Down
5 changes: 1 addition & 4 deletions extensions/typescript/src/utils/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,10 @@ export class TypeScriptServiceConfiguration {
}

private static extractGlobalTsdk(configuration: WorkspaceConfiguration): string | null {
let inspect = configuration.inspect('typescript.tsdk');
const inspect = configuration.inspect('typescript.tsdk');
if (inspect && inspect.globalValue && 'string' === typeof inspect.globalValue) {
return inspect.globalValue;
}
if (inspect && inspect.defaultValue && 'string' === typeof inspect.defaultValue) {
return inspect.defaultValue;
}
return null;
}

Expand Down
36 changes: 22 additions & 14 deletions extensions/typescript/src/utils/projectStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface ProjectHintedMap {
const fileLimit = 500;

class ExcludeHintItem {
public configFileName?: string;
private _item: vscode.StatusBarItem;
private _client: ITypescriptServiceClient;
private _currentHint: Hint;
Expand Down Expand Up @@ -133,36 +134,43 @@ function createLargeProjectMonitorFromTypeScript(item: ExcludeHintItem, client:
item.show();
const configFileName = body.projectName;
if (configFileName) {
item.configFileName = configFileName;
vscode.window.showWarningMessage<LargeProjectMessageItem>(item.getCurrentHint().message,
{
title: localize('large.label', "Configure Excludes"),
index: 0
}).then(selected => {
if (!selected || selected.index !== 0) {
return;
}
if (!isImplicitProjectConfigFile(configFileName)) {
vscode.workspace.openTextDocument(configFileName)
.then(vscode.window.showTextDocument);
} else {
const root = client.getWorkspaceRootForResource(vscode.Uri.file(configFileName));
if (root) {
openOrCreateConfigFile(
configFileName.match(/tsconfig\.?.*\.json/) !== null,
root);
}
if (selected && selected.index === 0) {
onConfigureExcludesSelected(client, configFileName);
}
});
}
}
});
}

function onConfigureExcludesSelected(client: ITypescriptServiceClient, configFileName: string) {
if (!isImplicitProjectConfigFile(configFileName)) {
vscode.workspace.openTextDocument(configFileName)
.then(vscode.window.showTextDocument);
} else {
const root = client.getWorkspaceRootForResource(vscode.Uri.file(configFileName));
if (root) {
openOrCreateConfigFile(
configFileName.match(/tsconfig\.?.*\.json/) !== null,
root);
}
}
}

export function create(client: ITypescriptServiceClient, isOpen: (path: string) => Promise<boolean>, memento: vscode.Memento) {
const toDispose: vscode.Disposable[] = [];

let item = new ExcludeHintItem(client);
const item = new ExcludeHintItem(client);
toDispose.push(vscode.commands.registerCommand('js.projectStatus.command', () => {
if (item.configFileName) {
onConfigureExcludesSelected(client, item.configFileName);
}
let { message } = item.getCurrentHint();
return vscode.window.showInformationMessage(message);
}));
Expand Down
Loading

0 comments on commit 754b68a

Please sign in to comment.