From c1906c79afdf71b91530415d173d0b1a51f6b693 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Tue, 20 Jun 2017 18:22:33 -0700 Subject: [PATCH] Update coffee grammar tests --- .../colorize-results/test-regex_coffee.json | 30 ++++++------ .../test/colorize-results/test_coffee.json | 48 +++++++++---------- .../parts/html/browser/html.contribution.ts | 13 +++-- .../parts/html/browser/htmlPreviewPart.ts | 5 +- .../workbench/parts/html/browser/webview.ts | 8 +++- .../workbench/parts/html/common/htmlInput.ts | 17 ++++++- 6 files changed, 73 insertions(+), 48 deletions(-) diff --git a/extensions/coffeescript/test/colorize-results/test-regex_coffee.json b/extensions/coffeescript/test/colorize-results/test-regex_coffee.json index 99cd587f50d..31fbd68304d 100644 --- a/extensions/coffeescript/test/colorize-results/test-regex_coffee.json +++ b/extensions/coffeescript/test/colorize-results/test-regex_coffee.json @@ -399,33 +399,33 @@ "c": "#{", "t": "source.coffee string.regexp.coffee source.coffee.embedded.source punctuation.section.embedded.coffee", "r": { - "dark_plus": "string.regexp: #D16969", - "light_plus": "string.regexp: #811F3F", - "dark_vs": "string.regexp: #D16969", - "light_vs": "string.regexp: #811F3F", - "hc_black": "string.regexp: #D16969" + "dark_plus": "punctuation.section.embedded.coffee: #569CD6", + "light_plus": "punctuation.section.embedded.coffee: #0000FF", + "dark_vs": "punctuation.section.embedded.coffee: #569CD6", + "light_vs": "punctuation.section.embedded.coffee: #0000FF", + "hc_black": "punctuation.section.embedded.coffee: #569CD6" } }, { "c": "name", "t": "source.coffee string.regexp.coffee source.coffee.embedded.source", "r": { - "dark_plus": "string.regexp: #D16969", - "light_plus": "string.regexp: #811F3F", - "dark_vs": "string.regexp: #D16969", - "light_vs": "string.regexp: #811F3F", - "hc_black": "string.regexp: #D16969" + "dark_plus": "source.coffee.embedded: #9CDCFE", + "light_plus": "source.coffee.embedded: #FF0000", + "dark_vs": "source.coffee.embedded: #9CDCFE", + "light_vs": "source.coffee.embedded: #FF0000", + "hc_black": "source.coffee.embedded: #D4D4D4" } }, { "c": "}", "t": "source.coffee string.regexp.coffee source.coffee.embedded.source punctuation.section.embedded.coffee", "r": { - "dark_plus": "string.regexp: #D16969", - "light_plus": "string.regexp: #811F3F", - "dark_vs": "string.regexp: #D16969", - "light_vs": "string.regexp: #811F3F", - "hc_black": "string.regexp: #D16969" + "dark_plus": "punctuation.section.embedded.coffee: #569CD6", + "light_plus": "punctuation.section.embedded.coffee: #0000FF", + "dark_vs": "punctuation.section.embedded.coffee: #569CD6", + "light_vs": "punctuation.section.embedded.coffee: #0000FF", + "hc_black": "punctuation.section.embedded.coffee: #569CD6" } }, { diff --git a/extensions/coffeescript/test/colorize-results/test_coffee.json b/extensions/coffeescript/test/colorize-results/test_coffee.json index 0dd197a1337..95338cf2f5f 100644 --- a/extensions/coffeescript/test/colorize-results/test_coffee.json +++ b/extensions/coffeescript/test/colorize-results/test_coffee.json @@ -278,11 +278,11 @@ "c": "#{", "t": "source.coffee string.quoted.double.coffee source.coffee.embedded.source punctuation.section.embedded.coffee", "r": { - "dark_plus": "string: #CE9178", - "light_plus": "string: #A31515", - "dark_vs": "string: #CE9178", - "light_vs": "string: #A31515", - "hc_black": "string: #CE9178" + "dark_plus": "punctuation.section.embedded.coffee: #569CD6", + "light_plus": "punctuation.section.embedded.coffee: #0000FF", + "dark_vs": "punctuation.section.embedded.coffee: #569CD6", + "light_vs": "punctuation.section.embedded.coffee: #0000FF", + "hc_black": "punctuation.section.embedded.coffee: #569CD6" } }, { @@ -291,8 +291,8 @@ "r": { "dark_plus": "variable: #9CDCFE", "light_plus": "variable: #001080", - "dark_vs": "string: #CE9178", - "light_vs": "string: #A31515", + "dark_vs": "source.coffee.embedded: #9CDCFE", + "light_vs": "source.coffee.embedded: #FF0000", "hc_black": "variable: #9CDCFE" } }, @@ -300,11 +300,11 @@ "c": "}", "t": "source.coffee string.quoted.double.coffee source.coffee.embedded.source punctuation.section.embedded.coffee", "r": { - "dark_plus": "string: #CE9178", - "light_plus": "string: #A31515", - "dark_vs": "string: #CE9178", - "light_vs": "string: #A31515", - "hc_black": "string: #CE9178" + "dark_plus": "punctuation.section.embedded.coffee: #569CD6", + "light_plus": "punctuation.section.embedded.coffee: #0000FF", + "dark_vs": "punctuation.section.embedded.coffee: #569CD6", + "light_vs": "punctuation.section.embedded.coffee: #0000FF", + "hc_black": "punctuation.section.embedded.coffee: #569CD6" } }, { @@ -531,11 +531,11 @@ "c": "#{", "t": "source.coffee string.quoted.double.coffee source.coffee.embedded.source punctuation.section.embedded.coffee", "r": { - "dark_plus": "string: #CE9178", - "light_plus": "string: #A31515", - "dark_vs": "string: #CE9178", - "light_vs": "string: #A31515", - "hc_black": "string: #CE9178" + "dark_plus": "punctuation.section.embedded.coffee: #569CD6", + "light_plus": "punctuation.section.embedded.coffee: #0000FF", + "dark_vs": "punctuation.section.embedded.coffee: #569CD6", + "light_vs": "punctuation.section.embedded.coffee: #0000FF", + "hc_black": "punctuation.section.embedded.coffee: #569CD6" } }, { @@ -544,8 +544,8 @@ "r": { "dark_plus": "variable: #9CDCFE", "light_plus": "variable: #001080", - "dark_vs": "string: #CE9178", - "light_vs": "string: #A31515", + "dark_vs": "source.coffee.embedded: #9CDCFE", + "light_vs": "source.coffee.embedded: #FF0000", "hc_black": "variable: #9CDCFE" } }, @@ -553,11 +553,11 @@ "c": "}", "t": "source.coffee string.quoted.double.coffee source.coffee.embedded.source punctuation.section.embedded.coffee", "r": { - "dark_plus": "string: #CE9178", - "light_plus": "string: #A31515", - "dark_vs": "string: #CE9178", - "light_vs": "string: #A31515", - "hc_black": "string: #CE9178" + "dark_plus": "punctuation.section.embedded.coffee: #569CD6", + "light_plus": "punctuation.section.embedded.coffee: #0000FF", + "dark_vs": "punctuation.section.embedded.coffee: #569CD6", + "light_vs": "punctuation.section.embedded.coffee: #0000FF", + "hc_black": "punctuation.section.embedded.coffee: #569CD6" } }, { diff --git a/src/vs/workbench/parts/html/browser/html.contribution.ts b/src/vs/workbench/parts/html/browser/html.contribution.ts index b2acd94c3f5..b123afcb034 100644 --- a/src/vs/workbench/parts/html/browser/html.contribution.ts +++ b/src/vs/workbench/parts/html/browser/html.contribution.ts @@ -10,7 +10,7 @@ import { CommandsRegistry } from 'vs/platform/commands/common/commands'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; import { Position as EditorPosition } from 'vs/platform/editor/common/editor'; -import { HtmlInput } from '../common/htmlInput'; +import { HtmlInput, HtmlInputOptions } from '../common/htmlInput'; import { HtmlPreviewPart } from 'vs/workbench/parts/html/browser/htmlPreviewPart'; import { Registry } from 'vs/platform/registry/common/platform'; import { EditorDescriptor } from 'vs/workbench/browser/parts/editor/baseEditor'; @@ -38,7 +38,7 @@ interface HtmlZoneParams { let warn = true; -CommandsRegistry.registerCommand('_workbench.htmlZone', function (accessor: ServicesAccessor, params: HtmlZoneParams) { +CommandsRegistry.registerCommand('_workbench.htmlZone', (accessor: ServicesAccessor, params: HtmlZoneParams) => { if (warn) { console.warn(`'_workbench.htmlZone' is an EXPERIMENTAL feature and therefore subject to CHANGE and REMOVAL without notice.`); @@ -69,10 +69,13 @@ CommandsRegistry.registerCommand('_workbench.htmlZone', function (accessor: Serv HtmlZoneController.getInstance(codeEditor).addZone(params.lineNumber, contents); }); - }); -CommandsRegistry.registerCommand('_workbench.previewHtml', function (accessor: ServicesAccessor, resource: URI | string, position?: EditorPosition, label?: string) { +const defaultOptions: HtmlInputOptions = { + enableJavaScript: true +}; + +CommandsRegistry.registerCommand('_workbench.previewHtml', (accessor: ServicesAccessor, resource: URI | string, position?: EditorPosition, label?: string, options: HtmlInputOptions = defaultOptions) => { const uri = resource instanceof URI ? resource : URI.parse(resource); label = label || uri.fsPath; @@ -91,7 +94,7 @@ CommandsRegistry.registerCommand('_workbench.previewHtml', function (accessor: S // Otherwise, create new input and open it if (!input) { - input = accessor.get(IInstantiationService).createInstance(HtmlInput, label, '', uri); + input = accessor.get(IInstantiationService).createInstance(HtmlInput, label, '', uri, options); } else { input.setName(label); // make sure to use passed in label } diff --git a/src/vs/workbench/parts/html/browser/htmlPreviewPart.ts b/src/vs/workbench/parts/html/browser/htmlPreviewPart.ts index 755a337fc24..b57b539a111 100644 --- a/src/vs/workbench/parts/html/browser/htmlPreviewPart.ts +++ b/src/vs/workbench/parts/html/browser/htmlPreviewPart.ts @@ -208,8 +208,11 @@ export class HtmlPreviewPart extends WebviewEditor { } this._modelChangeSubscription = this.model.onDidChangeContent(() => { - if (this.model) { + if (this.model && input instanceof HtmlInput) { this.scrollYPercentage = 0; + this.webview.options = { + enableJavascript: input.options.enableJavaScript + }; this.webview.contents = this.model.getLinesContent(); } }); diff --git a/src/vs/workbench/parts/html/browser/webview.ts b/src/vs/workbench/parts/html/browser/webview.ts index 6b45dbafd20..00316588404 100644 --- a/src/vs/workbench/parts/html/browser/webview.ts +++ b/src/vs/workbench/parts/html/browser/webview.ts @@ -60,7 +60,7 @@ export default class Webview { constructor( private parent: HTMLElement, private _styleElement: Element, - private options: WebviewOptions = {} + private _options: WebviewOptions = {} ) { this._webview = document.createElement('webview'); @@ -162,10 +162,14 @@ export default class Webview { this._send('initial-scroll-position', value); } + set options(options: WebviewOptions) { + this._options = options; + } + set contents(value: string[]) { this._send('content', { contents: value, - options: this.options + options: this._options }); } diff --git a/src/vs/workbench/parts/html/common/htmlInput.ts b/src/vs/workbench/parts/html/common/htmlInput.ts index e66c1e1f350..8f59598dca5 100644 --- a/src/vs/workbench/parts/html/common/htmlInput.ts +++ b/src/vs/workbench/parts/html/common/htmlInput.ts @@ -5,7 +5,22 @@ 'use strict'; import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput'; +import URI from 'vs/base/common/uri'; +import { ITextModelService } from 'vs/editor/common/services/resolverService'; + + +export interface HtmlInputOptions { + enableJavaScript?: boolean; +} export class HtmlInput extends ResourceEditorInput { - // marker class + constructor( + name: string, + description: string, + resource: URI, + public readonly options: HtmlInputOptions, + @ITextModelService textModelResolverService: ITextModelService + ) { + super(name, description, resource, textModelResolverService); + } }