Merge VS Code 1.26.1 (#2394)

* Squash merge commits for 1.26 (#1) (#2323)

* Polish tag search as per feedback (#55269)

* Polish tag search as per feedback

* Updated regex

* Allow users to opt-out of features that send online requests in the background (#55097)

* settings sweep #54690

* Minor css tweaks to enable eoverflow elipsis in more places (#55277)

* fix an issue with titlebarheight when not scaling with zoom

* Settings descriptions update #54690

* fixes #55209

* Settings editor - many padding fixes

* More space above level 2 label

* Fixing Cannot debug npm script using Yarn #55103

* Settings editor - show ellipsis when description overflows

* Settings editor - ... fix measuring around links, relayout

* Setting descriptions

* Settings editor - fix ... for some short lines, fix select container width

* Settings editor - overlay trees so scrollable shadow is full width

* Fix #54133 - missing extension settings after reload

* Settings color token description tweak

* Settings editor - disable overflow indicator temporarily, needs to be faster

* Added command to Run the selected npm script

* fixes #54452

* fixes #54929

* fixes #55248

* prefix command with extension name

* Contribute run selected to the context menu

* node-debug@1.26.6

* Allow terminal rendererType to be swapped out at runtime

Part of #53274
Fixes #55344

* Settings editor - fix not focusing search when restoring editor
setInput must be actually async. Will be fixed naturally when we aren't using winJS promises...

* Settings editor - TOC should only expand the section with a selected item

* Bump node-debug2

* Settings editor - Tree focus outlines

* Settings editor - don't blink the scrollbar when toc selection changes
And hide TOC correctly when the editor is narrow

* Settings editor - header rows should not be selectable

* fixes #54877

* change debug assignee to isi

* Settings sweep (#54690)

* workaround for #55051

* Settings sweep (#54690)

* settings sweep

#54690

* Don't try closing tags when you type > after another >

* Describe what implementation code lens does

Fixes #55370

* fix javadoc formatter setting description

* fixes #55325

* update to officical TS version

* Settings editor - Even more padding, use semibold instead of bold

* Fix #55357 - fix TOC twistie

* fixes #55288

* explorer: refresh on di change file system provider registration

fixes #53256

* Disable push to Linux repo to test standalone publisher

* New env var to notify log level to extensions #54001

* Disable snippets in extension search (when not in suggest dropdown) (#55281)

* Disable snippits in extension search (when not in suggest dropdown)

* Add monaco input contributions

* Fix bug preventing snippetSuggestions from taking effect in sub-editors

* Latest emmet helper to fix #52366

* Fix comment updates for threads within same file

* Allow extensions to log telemetry to log files #54001

* Pull latest css grammar

* files.exclude control - use same style for "add" vs "edit"

* files.exclude control - focus/keyboard behavior

* don't show menubar too early

* files.exclude - better styling

* Place cursor at end of extensions search box on autofill (#55254)

* Place cursor at end of extensions search box on autofill

* Use position instead of selection

* fix linux build issue (empty if block)

* Settings editor - fix extension category prefixes

* Settings editor - add simple ellipsis for first line that overflows, doesn't cover case when first line does not overflow but there is more text, TODO

* File/Text search provider docs

* Fixes #52655

* Include epoch (#55008)

* Fixes #53385

* Fixes #49480

*  VS Code Insiders (Users) not opening Fixes #55353

* Better handling of the case when the extension host fails to start

* Fixes #53966

*  Remove confusing Start from wordPartLeft commands ID

* vscode-xterm@3.6.0-beta12

Fixes #55488

* Initial size is set to infinity!! Fixes #55461

* Polish embeddedEditorBackground

* configuration service misses event

* Fix #55224 - fix duplicate results in multiroot workspace from splitting the diskseach query

* Select all not working in issue reporter on mac, fixes #55424

* Disable fuzzy matching for extensions autosuggest (#55498)

* Fix clipping of extensions search border in some third party themes (#55504)

* fixes #55538

* Fix bug causing an aria alert to not be shown the third time
 (and odd numbers thereafter)

* Settings editor - work around rendering glitch with webkit-line-clamp

* Settings editor - revert earlier '...' changes

* Settings editor - move enumDescription to its own div, because it disturbs -webkit-line-clamp for some reason

* Settings editor - better overflow indicator

* Don't show existing filters in autocomplete (#55495)

* Dont show existing filters in autocomplete

* Simplify

* Settings Editor: Add aria labels for input elements Fixes: #54836 (#55543)

* fixes #55223

* Update vscode-css-languageservice to 3.0.10-next.1

* Fix #55509 - settings navigation

* Fix #55519

* Fix #55520

* FIx #55524

* Fix #55556 - include wordSeparators in all search queries, so findTextInFiles can respect isWordMatch correctly

* oss updates for endgame

* Fix unit tests

* fixes #55522

* Avoid missing manifest error from bubbling up #54757

* Settings format crawl

* Search provider - Fix FileSearchProvider to return array, not progress

* Fix #55598

* Settings editor - fix NPE rendering settings with no description

* dont render inden guides in search box (#55600)

* fixes #55454

* More settings crawl

* Another change for #55598 - maxResults applies to FileSearch and TextSearch but not FileIndex

* Fix FileSearchProvider unit tests for progress change

* fixes #55561

* Settings description update for #54690

* Update setting descriptions for online services

* Minor edits

* fixes #55513

* fixes #55451

* Fix #55612 - fix findTextInFiles cancellation

* fixes #55539

* More setting description tweaks

* Setting to disable online experiments #54354

* fixes #55507

* fixes #55515

* Show online services action only in Insiders for now

* Settings editor - change toc behavior default to 'filter'

* Settings editor - nicer filter count style during search

* Fix #55617 - search viewlet icons

* Settings editor - better styling for element count indicator

* SearchProvider - fix NPE when searching extraFileResources

* Allow extends to work without json suffix

Fixes #16905

* Remove accessability options logic entirely

Follow up on #55451

* use latest version of DAP

* fixes #55490

* fixes #55122

* fixes #52332

* Avoid assumptions about git: URIs (fixes #36236)

* relative path for descriptions

* resourece: get rid of isFile context key

fixes #48275

* Register previous ids for compatibility (#53497)

* more tuning for #48275

* no need to always re-read "files explorer"

fixes #52003

* read out active composites properly

fixes #51967

* Update link colors for hc theme to meet color contrast ratio, fixes #55651

Also updated link color for `textLinkActiveForeground` to be the same as `textLinkForeground` as it wasn't properly updated

* detect 'winpty-agent.exe'; fixes #55672

* node-debug@1.26.7

* reset counter on new label

* Settings editor - fix multiple setting links in one description

* Settings editor - color code blocks in setting descriptions, fix #55532

* Settings editor - hover color in TOC

* Settings editor - fix navigation NPE

* Settings editor - fix text control width

* Settings editor - maybe fix #55684

* Fix bug causing cursor to not move on paste

* fixes #53582

* Use ctrlCmd instead of ctrl for go down from search box

* fixes #55264

* fixes #55456

* filter for spcaes before triggering search (#55611)

* Fix #55698 - don't lose filtered TOC counts when refreshing TOC

* fixes #55421

* fixes #28979

* fixes #55576

* only add check for updates to windows/linux help

* readonly files: append decoration to label

fixes #53022

* debug: do not show toolbar while initialising

fixes #55026

* Opening launch.json should not activate debug extensions

fixes #55029

* fixes #55435

* fixes #55434

* fixes #55439

* trigger menu only on altkey up

* Fix #50555 - fix settings editor memory leak

* Fix #55712 - no need to focus 'a' anymore when restoring control focus after tree render

* fixes #55335

* proper fix for readonly model

fixes #53022

* improve FoldingRangeKind spec (for #55686)

* Use class with static fields (fixes #55494)

* Fixes #53671

* fixes #54630

* [html] should disable ionic suggestions by default. Currently forces deprecated Ionic v1 suggestions in .html files while typing. Fixes #53324

* cleanup deps

* debug issues back to andre

* update electron for smoketest

* Fix #55757 - prevent settings tabs from overflowing

* Fix #53897 - revert setting menu defaults to old editor

* Add enum descriptions to `typescript.preferences.importModuleSpecifier`

* Fix #55767 - leaking style elements from settings editor

* Fix #55521 - prevent flashing when clicking in exclude control

* Update Git modified color for contrast ratio, fixes #53140

* Revert "Merge branch 'master' of github.com:Microsoft/vscode"

This reverts commit bf46b6bfbae0cab99c2863e1244a916181fa9fbc, reversing
changes made to e275a424483dfb4ed33b428c97d5e2c441d6b917.

* Revert "Revert "Merge branch 'master' of github.com:Microsoft/vscode""

This reverts commit 53949d963f39e40757557c6526332354a31d9154.

* don't ask to install an incomplete menu

* Fix NPE in terminal AccessibilityManager

Fixes #55744

* don't display fallback menu unless we've closed the last window

* fixes #55547

* Fix smoke tests for extension search box

* Update OSSREADME.json for Electron 2.0.5

* Update distro

Includes Chromium license changes

* fix #55455

* fix #55865

* fixes #55893

* Fix bug causing workspace recommendations to go away upon ignoring a recommendation (#55805)

* Fix bug causing workspace recommendations to go away upon ignoring a recommendation

* ONly show on @recommended or @recommended:workspace

* Make more consistant

* Fix #55911

* Understand json activity (#55926)

* Understand json file activity

* Refactoring

* adding composer.json

* Distro update for experiments

* use terminal.processId for auto-attach; fixes #55918

* Reject invalid URI with vscode.openFolder (for #55891)

* improve win32 setup system vs user detection

fixes #55840

fixes #55840

delay winreg import

related to #55840

show notification earlier

related to #55840

fix #55840

update inno setup message

related to #55840

* Fix #55593 - this code only operates on local paths, so use fsPath and Uri.file instead

* Bring back the old menu due to electron 2.0 issues (#55913)

* add the old menu back for native menus

* make menu labels match

* `vscode.openFolder`: treat missing URI schema gracefully (for #55891)

* delay EH reattach; fixes #55955

* Mark all json files under appSettingsHome as settings

* Use localized strings for telemetry opt-out

* Exception when saving file editor opened from remote file provider (fixes #55051)

* Remove terminal menu from stable

Fixes 56003

* VSCode Insiders crashes on open with TypeError: Cannot read property 'lastIndexOf' of undefined. Fixes #54933

* improve fix for #55891

* fix #55916

* Improve #55891

* increase EH debugging restart delay; fixes #55955

* Revert "Don't include non-resource entries in history quick pick"

This reverts commit 37209a838e9f7e9abe6dc53ed73cdf1e03b72060.

* Diff editor: horizontal scrollbar height is smaller (fixes #56062)

* improve openFolder uri fix (correctly treat backslashes)

* fixes #56116
repair ipc for native menubar keybindings

* Fix #56240 - Open the JSON settings editor instead of the UI editor

* Fix #55536

* uriDisplay: if no formatter is registered fall back to getPathlabel

fixes #56104

* VSCode hangs when opening python file. Fixes #56377

* VS Code Hangs When Opening Specific PowerShell File. Fixes #56430

* Fix #56433 - search extraFileResources even when no folders open

* Workaround #55649

* Fix in master #56371

* Fix tests #56371

* Fix in master #56317

* increase version to 1.26.1

* Fixes #56387: Handle SIGPIPE in extension host

* fixes #56185

* Fix merge issues (part 1)

* Fix build breaks (part 1)

* Build breaks (part 2)

* Build breaks (part 3)

* More build breaks (part 4)

* Fix build breaks (part 5)

* WIP

* Fix menus

* Render query result and message panels (#2363)

* Put back query editor hot exit changes

* Fix grid changes that broke profiler (#2365)

* Update APIs for saving query editor state

* Fix restore view state for profiler and edit data

* Updating custom default themes to support 4.5:1 contrast ratio

* Test updates

* Fix Extension Manager and Windows Setup

* Update license headers

* Add appveyor and travis files back

* Fix hidden modal dropdown issue
This commit is contained in:
Karl Burtram
2018-09-04 14:55:00 -07:00
committed by GitHub
parent 3763278366
commit 81329fa7fa
2638 changed files with 118456 additions and 64012 deletions

View File

@@ -30,7 +30,7 @@ import URI from 'vs/base/common/uri';
import { Selection } from 'vs/editor/common/core/selection';
import * as browser from 'vs/base/browser/browser';
import { IEditorConstructionOptions } from 'vs/editor/standalone/browser/standaloneCodeEditor';
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
const CONTEXT_ACCESSIBILITY_WIDGET_VISIBLE = new RawContextKey<boolean>('accessibilityHelpWidgetVisible', false);
@@ -342,7 +342,8 @@ class ShowAccessibilityHelpAction extends EditorAction {
precondition: null,
kbOpts: {
kbExpr: EditorContextKeys.focus,
primary: (browser.isIE ? KeyMod.CtrlCmd | KeyCode.F1 : KeyMod.Alt | KeyCode.F1)
primary: (browser.isIE ? KeyMod.CtrlCmd | KeyCode.F1 : KeyMod.Alt | KeyCode.F1),
weight: KeybindingWeight.EditorContrib
}
});
}
@@ -366,7 +367,7 @@ registerEditorCommand(
precondition: CONTEXT_ACCESSIBILITY_WIDGET_VISIBLE,
handler: x => x.hide(),
kbOpts: {
weight: KeybindingsRegistry.WEIGHT.editorContrib(100),
weight: KeybindingWeight.EditorContrib + 100,
kbExpr: EditorContextKeys.focus,
primary: KeyCode.Escape,
secondary: [KeyMod.Shift | KeyCode.Escape]

View File

@@ -42,7 +42,7 @@ export class Colorizer {
let render = (str: string) => {
domNode.innerHTML = str;
};
return this.colorize(modeService, text, mimeType, options).then(render, (err) => console.error(err), render);
return this.colorize(modeService, text, mimeType, options).then(render, (err) => console.error(err));
}
private static _tokenizationSupportChangedPromise(language: string): TPromise<void> {
@@ -54,7 +54,7 @@ export class Colorizer {
}
};
return new TPromise<void>((c, e, p) => {
return new TPromise<void>((c, e) => {
listener = TokenizationRegistry.onDidChange((e) => {
if (e.changedLanguages.indexOf(language) >= 0) {
stopListening();
@@ -100,6 +100,7 @@ export class Colorizer {
let renderResult = renderViewLine(new RenderLineInput(
false,
line,
false,
isBasicASCII,
containsRTL,
0,
@@ -152,6 +153,7 @@ function _fakeColorize(lines: string[], tabSize: number): string {
let renderResult = renderViewLine(new RenderLineInput(
false,
line,
false,
isBasicASCII,
containsRTL,
0,
@@ -186,6 +188,7 @@ function _actualColorize(lines: string[], tabSize: number, tokenizationSupport:
let renderResult = renderViewLine(new RenderLineInput(
false,
line,
false,
isBasicASCII,
containsRTL,
0,

View File

@@ -18,6 +18,7 @@ import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { ITextModel } from 'vs/editor/common/model';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
interface ParseResult {
position: Position;
@@ -153,7 +154,8 @@ export class GotoLineAction extends BaseEditorQuickOpenAction {
kbOpts: {
kbExpr: EditorContextKeys.focus,
primary: KeyMod.CtrlCmd | KeyCode.KEY_G,
mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_G }
mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_G },
weight: KeybindingWeight.EditorContrib
}
});
}

View File

@@ -18,6 +18,7 @@ import { registerEditorAction, ServicesAccessor } from 'vs/editor/browser/editor
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import * as browser from 'vs/base/browser/browser';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
export class EditorActionCommandEntry extends QuickOpenEntryGroup {
private key: string;
@@ -79,9 +80,12 @@ export class QuickCommandAction extends BaseEditorQuickOpenAction {
precondition: null,
kbOpts: {
kbExpr: EditorContextKeys.focus,
primary: (browser.isIE ? KeyMod.Alt | KeyCode.F1 : KeyCode.F1)
primary: (browser.isIE ? KeyMod.Alt | KeyCode.F1 : KeyCode.F1),
weight: KeybindingWeight.EditorContrib
},
menuOpts: {
group: 'z_commands',
order: 1
}
});
}

View File

@@ -15,13 +15,14 @@ import { IContext, IHighlight, QuickOpenEntryGroup, QuickOpenModel } from 'vs/ba
import { IAutoFocus, Mode } from 'vs/base/parts/quickopen/common/quickOpen';
import { ScrollType } from 'vs/editor/common/editorCommon';
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { SymbolInformation, DocumentSymbolProviderRegistry, symbolKindToCssClass, IOutline, Location } from 'vs/editor/common/modes';
import { DocumentSymbol, DocumentSymbolProviderRegistry, symbolKindToCssClass } from 'vs/editor/common/modes';
import { BaseEditorQuickOpenAction, IDecorator } from './editorQuickOpen';
import { getDocumentSymbols } from 'vs/editor/contrib/quickOpen/quickOpen';
import { registerEditorAction, ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { Range } from 'vs/editor/common/core/range';
import { Range, IRange } from 'vs/editor/common/core/range';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
let SCOPE_PREFIX = ':';
@@ -120,7 +121,8 @@ export class QuickOutlineAction extends BaseEditorQuickOpenAction {
precondition: EditorContextKeys.hasDocumentSymbolProvider,
kbOpts: {
kbExpr: EditorContextKeys.focus,
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_O
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_O,
weight: KeybindingWeight.EditorContrib
},
menuOpts: {
group: 'navigation',
@@ -138,16 +140,16 @@ export class QuickOutlineAction extends BaseEditorQuickOpenAction {
}
// Resolve outline
return getDocumentSymbols(model).then((result: IOutline) => {
if (result.entries.length === 0) {
return getDocumentSymbols(model).then((result: DocumentSymbol[]) => {
if (result.length === 0) {
return;
}
this._run(editor, result.entries);
this._run(editor, result);
});
}
private _run(editor: ICodeEditor, result: SymbolInformation[]): void {
private _run(editor: ICodeEditor, result: DocumentSymbol[]): void {
this._show(this.getController(editor), {
getModel: (value: string): QuickOpenModel => {
return new QuickOpenModel(this.toQuickOpenEntries(editor, result, value));
@@ -167,11 +169,11 @@ export class QuickOutlineAction extends BaseEditorQuickOpenAction {
});
}
private symbolEntry(name: string, type: string, description: string, location: Location, highlights: IHighlight[], editor: ICodeEditor, decorator: IDecorator): SymbolEntry {
return new SymbolEntry(name, type, description, Range.lift(location.range), highlights, editor, decorator);
private symbolEntry(name: string, type: string, description: string, range: IRange, highlights: IHighlight[], editor: ICodeEditor, decorator: IDecorator): SymbolEntry {
return new SymbolEntry(name, type, description, Range.lift(range), highlights, editor, decorator);
}
private toQuickOpenEntries(editor: ICodeEditor, flattened: SymbolInformation[], searchValue: string): SymbolEntry[] {
private toQuickOpenEntries(editor: ICodeEditor, flattened: DocumentSymbol[], searchValue: string): SymbolEntry[] {
const controller = this.getController(editor);
let results: SymbolEntry[] = [];
@@ -197,7 +199,7 @@ export class QuickOutlineAction extends BaseEditorQuickOpenAction {
}
// Add
results.push(this.symbolEntry(label, symbolKindToCssClass(element.kind), description, element.location, highlights, editor, controller));
results.push(this.symbolEntry(label, symbolKindToCssClass(element.kind), description, element.range, highlights, editor, controller));
}
}

View File

@@ -4,17 +4,13 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { IEditorService } from 'vs/platform/editor/common/editor';
import { IInstantiationService, optional } from 'vs/platform/instantiation/common/instantiation';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { registerEditorContribution } from 'vs/editor/browser/editorExtensions';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { ReferencesController } from 'vs/editor/contrib/referenceSearch/referencesController';
@@ -23,29 +19,21 @@ export class StandaloneReferencesController extends ReferencesController {
public constructor(
editor: ICodeEditor,
@IContextKeyService contextKeyService: IContextKeyService,
@IEditorService editorService: IEditorService,
@ITextModelService textModelResolverService: ITextModelService,
@ICodeEditorService editorService: ICodeEditorService,
@INotificationService notificationService: INotificationService,
@IInstantiationService instantiationService: IInstantiationService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IStorageService storageService: IStorageService,
@IThemeService themeService: IThemeService,
@IConfigurationService configurationService: IConfigurationService,
@optional(IEnvironmentService) environmentService: IEnvironmentService
) {
super(
true,
editor,
contextKeyService,
editorService,
textModelResolverService,
notificationService,
instantiationService,
contextService,
storageService,
themeService,
configurationService,
environmentService
);
}
}

View File

@@ -4,13 +4,11 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { Schemas } from 'vs/base/common/network';
import Severity from 'vs/base/common/severity';
import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { IConfigurationService, IConfigurationChangeEvent, IConfigurationOverrides } from 'vs/platform/configuration/common/configuration';
import { ISingleFolderWorkspaceIdentifier, IWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
import { IEditor, IEditorInput, IEditorOptions, IEditorService, IResourceInput, Position } from 'vs/platform/editor/common/editor';
import { IConfigurationService, IConfigurationChangeEvent, IConfigurationOverrides, IConfigurationData } from 'vs/platform/configuration/common/configuration';
import { IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces';
import { ICommandService, ICommand, ICommandEvent, ICommandHandler, CommandsRegistry } from 'vs/platform/commands/common/commands';
import { AbstractKeybindingService } from 'vs/platform/keybinding/common/abstractKeybindingService';
import { USLayoutResolvedKeybinding } from 'vs/platform/keybinding/common/usLayoutResolvedKeybinding';
@@ -26,7 +24,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IProgressService, IProgressRunner } from 'vs/platform/progress/common/progress';
import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration';
import { ITextModelService, ITextModelContentProvider, ITextEditorModel } from 'vs/editor/common/services/resolverService';
import { IDisposable, IReference, ImmortalReference, combinedDisposable } from 'vs/base/common/lifecycle';
import { IDisposable, IReference, ImmortalReference, combinedDisposable, toDisposable } from 'vs/base/common/lifecycle';
import * as dom from 'vs/base/browser/dom';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { KeybindingsRegistry, IKeybindingItem } from 'vs/platform/keybinding/common/keybindingsRegistry';
@@ -36,39 +34,17 @@ import { ITelemetryService, ITelemetryInfo } from 'vs/platform/telemetry/common/
import { ResolvedKeybinding, Keybinding, createKeybinding, SimpleKeybinding } from 'vs/base/common/keyCodes';
import { ResolvedKeybindingItem } from 'vs/platform/keybinding/common/resolvedKeybindingItem';
import { OS } from 'vs/base/common/platform';
import { IRange } from 'vs/editor/common/core/range';
import { Range } from 'vs/editor/common/core/range';
import { ITextModel } from 'vs/editor/common/model';
import { INotificationService, INotification, INotificationHandle, NoOpNotification, IPromptChoice } from 'vs/platform/notification/common/notification';
import { IConfirmation, IConfirmationResult, IDialogService, IDialogOptions } from 'vs/platform/dialogs/common/dialogs';
import { IPosition, Position as Pos } from 'vs/editor/common/core/position';
export class SimpleEditor implements IEditor {
public input: IEditorInput;
public options: IEditorOptions;
public position: Position;
public _widget: editorCommon.IEditor;
constructor(editor: editorCommon.IEditor) {
this._widget = editor;
}
public getId(): string { return 'editor'; }
public getControl(): editorCommon.IEditor { return this._widget; }
public focus(): void { this._widget.focus(); }
public isVisible(): boolean { return true; }
public withTypedEditor<T>(codeEditorCallback: (editor: ICodeEditor) => T, diffEditorCallback: (editor: IDiffEditor) => T): T {
if (isCodeEditor(this._widget)) {
// Single Editor
return codeEditorCallback(<ICodeEditor>this._widget);
} else {
// Diff Editor
return diffEditorCallback(<IDiffEditor>this._widget);
}
}
}
import { isEditorConfigurationKey, isDiffEditorConfigurationKey } from 'vs/editor/common/config/commonEditorConfig';
import { IBulkEditService, IBulkEditOptions, IBulkEditResult } from 'vs/editor/browser/services/bulkEditService';
import { WorkspaceEdit, isResourceTextEdit, TextEdit } from 'vs/editor/common/modes';
import { IModelService } from 'vs/editor/common/services/modelService';
import { EditOperation } from 'vs/editor/common/core/editOperation';
import { localize } from 'vs/nls';
export class SimpleModel implements ITextEditorModel {
@@ -101,94 +77,29 @@ export interface IOpenEditorDelegate {
(url: string): boolean;
}
export class SimpleEditorService implements IEditorService {
public _serviceBrand: any;
private editor: SimpleEditor;
private openEditorDelegate: IOpenEditorDelegate;
constructor() {
this.openEditorDelegate = null;
}
public setEditor(editor: editorCommon.IEditor): void {
this.editor = new SimpleEditor(editor);
}
public setOpenEditorDelegate(openEditorDelegate: IOpenEditorDelegate): void {
this.openEditorDelegate = openEditorDelegate;
}
public openEditor(typedData: IResourceInput, sideBySide?: boolean): TPromise<IEditor> {
return TPromise.as(this.editor.withTypedEditor(
(editor) => this.doOpenEditor(editor, typedData),
(diffEditor) => (
this.doOpenEditor(diffEditor.getOriginalEditor(), typedData) ||
this.doOpenEditor(diffEditor.getModifiedEditor(), typedData)
)
));
}
private doOpenEditor(editor: ICodeEditor, data: IResourceInput): IEditor {
let model = this.findModel(editor, data);
if (!model) {
if (data.resource) {
if (this.openEditorDelegate) {
this.openEditorDelegate(data.resource.toString());
return null;
} else {
let schema = data.resource.scheme;
if (schema === Schemas.http || schema === Schemas.https) {
// This is a fully qualified http or https URL
dom.windowOpenNoOpener(data.resource.toString());
return this.editor;
}
}
}
return null;
}
let selection = <IRange>data.options.selection;
if (selection) {
if (typeof selection.endLineNumber === 'number' && typeof selection.endColumn === 'number') {
editor.setSelection(selection);
editor.revealRangeInCenter(selection, editorCommon.ScrollType.Immediate);
} else {
let pos = {
lineNumber: selection.startLineNumber,
column: selection.startColumn
};
editor.setPosition(pos);
editor.revealPositionInCenter(pos, editorCommon.ScrollType.Immediate);
}
}
return this.editor;
}
private findModel(editor: ICodeEditor, data: IResourceInput): ITextModel {
let model = editor.getModel();
if (model.uri.toString() !== data.resource.toString()) {
return null;
}
return model;
function withTypedEditor<T>(widget: editorCommon.IEditor, codeEditorCallback: (editor: ICodeEditor) => T, diffEditorCallback: (editor: IDiffEditor) => T): T {
if (isCodeEditor(widget)) {
// Single Editor
return codeEditorCallback(<ICodeEditor>widget);
} else {
// Diff Editor
return diffEditorCallback(<IDiffEditor>widget);
}
}
export class SimpleEditorModelResolverService implements ITextModelService {
public _serviceBrand: any;
private editor: SimpleEditor;
private editor: editorCommon.IEditor;
public setEditor(editor: editorCommon.IEditor): void {
this.editor = new SimpleEditor(editor);
this.editor = editor;
}
public createModelReference(resource: URI): TPromise<IReference<ITextEditorModel>> {
let model: ITextModel;
model = this.editor.withTypedEditor(
model = withTypedEditor(this.editor,
(editor) => this.findModel(editor, resource),
(diffEditor) => this.findModel(diffEditor.getOriginalEditor(), resource) || this.findModel(diffEditor.getModifiedEditor(), resource)
);
@@ -319,11 +230,9 @@ export class StandaloneCommandService implements ICommandService {
public addCommand(command: ICommand): IDisposable {
const { id } = command;
this._dynamicCommands[id] = command;
return {
dispose: () => {
delete this._dynamicCommands[id];
}
};
return toDisposable(() => {
delete this._dynamicCommands[id];
});
}
public executeCommand<T>(id: string, ...args: any[]): TPromise<T> {
@@ -358,7 +267,7 @@ export class StandaloneKeybindingService extends AbstractKeybindingService {
this._cachedResolver = null;
this._dynamicKeybindings = [];
this.toDispose.push(dom.addDisposableListener(domNode, dom.EventType.KEY_DOWN, (e: KeyboardEvent) => {
this._register(dom.addDisposableListener(domNode, dom.EventType.KEY_DOWN, (e: KeyboardEvent) => {
let keyEvent = new StandardKeyboardEvent(e);
let shouldPreventDefault = this._dispatch(keyEvent, keyEvent.target);
if (shouldPreventDefault) {
@@ -378,18 +287,16 @@ export class StandaloneKeybindingService extends AbstractKeybindingService {
weight2: 0
});
toDispose.push({
dispose: () => {
for (let i = 0; i < this._dynamicKeybindings.length; i++) {
let kb = this._dynamicKeybindings[i];
if (kb.command === commandId) {
this._dynamicKeybindings.splice(i, 1);
this.updateResolver({ source: KeybindingSource.Default });
return;
}
toDispose.push(toDisposable(() => {
for (let i = 0; i < this._dynamicKeybindings.length; i++) {
let kb = this._dynamicKeybindings[i];
if (kb.command === commandId) {
this._dynamicKeybindings.splice(i, 1);
this.updateResolver({ source: KeybindingSource.Default });
return;
}
}
});
}));
let commandService = this._commandService;
if (commandService instanceof StandaloneCommandService) {
@@ -419,6 +326,10 @@ export class StandaloneKeybindingService extends AbstractKeybindingService {
return this._cachedResolver;
}
protected _documentHasFocus(): boolean {
return document.hasFocus();
}
private _toNormalizedKeybindingItems(items: IKeybindingItem[], isDefault: boolean): ResolvedKeybindingItem[] {
let result: ResolvedKeybindingItem[] = [], resultLen = 0;
for (let i = 0, len = items.length; i < len; i++) {
@@ -495,6 +406,7 @@ export class SimpleConfigurationService implements IConfigurationService {
}
public updateValue(key: string, value: any, arg3?: any, arg4?: any): TPromise<void> {
this.configuration().updateValue(key, value);
return TPromise.as(null);
}
@@ -516,7 +428,7 @@ export class SimpleConfigurationService implements IConfigurationService {
return TPromise.as(null);
}
public getConfigurationData() {
public getConfigurationData(): IConfigurationData {
return null;
}
}
@@ -620,3 +532,61 @@ export class SimpleWorkspaceContextService implements IWorkspaceContextService {
return true;
}
}
export function applyConfigurationValues(configurationService: IConfigurationService, source: any, isDiffEditor: boolean): void {
if (!source) {
return;
}
if (!(configurationService instanceof SimpleConfigurationService)) {
return;
}
Object.keys(source).forEach((key) => {
if (isEditorConfigurationKey(key)) {
configurationService.updateValue(`editor.${key}`, source[key]);
}
if (isDiffEditor && isDiffEditorConfigurationKey(key)) {
configurationService.updateValue(`diffEditor.${key}`, source[key]);
}
});
}
export class SimpleBulkEditService implements IBulkEditService {
_serviceBrand: any;
constructor(private readonly _modelService: IModelService) {
//
}
apply(workspaceEdit: WorkspaceEdit, options: IBulkEditOptions): TPromise<IBulkEditResult> {
let edits = new Map<ITextModel, TextEdit[]>();
for (let edit of workspaceEdit.edits) {
if (!isResourceTextEdit(edit)) {
return TPromise.wrapError(new Error('bad edit - only text edits are supported'));
}
let model = this._modelService.getModel(edit.resource);
if (!model) {
return TPromise.wrapError(new Error('bad edit - model not found'));
}
let array = edits.get(model);
if (!array) {
array = [];
}
edits.set(model, array.concat(edit.edits));
}
let totalEdits = 0;
let totalFiles = 0;
edits.forEach((edits, model) => {
model.applyEdits(edits.map(edit => EditOperation.replaceMove(Range.lift(edit.range), edit.text)));
totalFiles += 1;
totalEdits += edits.length;
});
return TPromise.as({
selection: undefined,
ariaSummary: localize('summary', 'Made {0} edits in {1} files', totalEdits, totalFiles)
});
}
}

View File

@@ -5,7 +5,7 @@
'use strict';
import { empty as emptyDisposable, IDisposable, combinedDisposable } from 'vs/base/common/lifecycle';
import { Disposable, IDisposable, combinedDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { TPromise } from 'vs/base/common/winjs.base';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@@ -16,9 +16,9 @@ import { IModelChangedEvent } from 'vs/editor/common/editorCommon';
import { ITextModel } from 'vs/editor/common/model';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
import { StandaloneKeybindingService } from 'vs/editor/standalone/browser/simpleServices';
import { IEditorContextViewService } from 'vs/editor/standalone/browser/standaloneServices';
import { CodeEditor } from 'vs/editor/browser/codeEditor';
import { StandaloneKeybindingService, applyConfigurationValues } from 'vs/editor/standalone/browser/simpleServices';
import { ContextViewService } from 'vs/platform/contextview/browser/contextViewService';
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget';
import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser';
import { IStandaloneThemeService } from 'vs/editor/standalone/common/standaloneThemeService';
@@ -30,6 +30,7 @@ import * as aria from 'vs/base/browser/ui/aria/aria';
import * as nls from 'vs/nls';
import * as browser from 'vs/base/browser/browser';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
/**
* Description of an action contribution
@@ -152,7 +153,7 @@ function createAriaDomNode() {
/**
* A code editor to be used both by the standalone editor and the standalone diff editor.
*/
export class StandaloneCodeEditor extends CodeEditor implements IStandaloneCodeEditor {
export class StandaloneCodeEditor extends CodeEditorWidget implements IStandaloneCodeEditor {
private _standaloneKeybindingService: StandaloneKeybindingService;
@@ -174,7 +175,7 @@ export class StandaloneCodeEditor extends CodeEditor implements IStandaloneCodeE
? nls.localize('accessibilityHelpMessageIE', "Press Ctrl+F1 for Accessibility Options.")
: nls.localize('accessibilityHelpMessage', "Press Alt+F1 for Accessibility Options.")
);
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService);
super(domElement, options, {}, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService);
if (keybindingService instanceof StandaloneKeybindingService) {
this._standaloneKeybindingService = keybindingService;
@@ -205,7 +206,7 @@ export class StandaloneCodeEditor extends CodeEditor implements IStandaloneCodeE
}
if (!this._standaloneKeybindingService) {
console.warn('Cannot add keybinding because the editor is configured with an unrecognized KeybindingService');
return emptyDisposable;
return Disposable.None;
}
// Read descriptor options
@@ -271,11 +272,9 @@ export class StandaloneCodeEditor extends CodeEditor implements IStandaloneCodeE
// Store it under the original id, such that trigger with the original id will work
this._actions[id] = internalAction;
toDispose.push({
dispose: () => {
delete this._actions[id];
}
});
toDispose.push(toDisposable(() => {
delete this._actions[id];
}));
return combinedDisposable(toDispose);
}
@@ -283,7 +282,8 @@ export class StandaloneCodeEditor extends CodeEditor implements IStandaloneCodeE
export class StandaloneEditor extends StandaloneCodeEditor implements IStandaloneCodeEditor {
private _contextViewService: IEditorContextViewService;
private _contextViewService: ContextViewService;
private readonly _configurationService: IConfigurationService;
private _ownsModel: boolean;
constructor(
@@ -298,7 +298,9 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon
@IContextViewService contextViewService: IContextViewService,
@IStandaloneThemeService themeService: IStandaloneThemeService,
@INotificationService notificationService: INotificationService,
@IConfigurationService configurationService: IConfigurationService
) {
applyConfigurationValues(configurationService, options, false);
options = options || {};
if (typeof options.theme === 'string') {
themeService.setTheme(options.theme);
@@ -307,7 +309,8 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon
delete options.model;
super(domElement, options, instantiationService, codeEditorService, commandService, contextKeyService, keybindingService, themeService, notificationService);
this._contextViewService = <IEditorContextViewService>contextViewService;
this._contextViewService = <ContextViewService>contextViewService;
this._configurationService = configurationService;
this._register(toDispose);
if (typeof model === 'undefined') {
@@ -331,6 +334,11 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon
super.dispose();
}
public updateOptions(newOptions: IEditorOptions): void {
applyConfigurationValues(this._configurationService, newOptions, false);
super.updateOptions(newOptions);
}
_attachModel(model: ITextModel): void {
super._attachModel(model);
if (this._view) {
@@ -349,7 +357,8 @@ export class StandaloneEditor extends StandaloneCodeEditor implements IStandalon
export class StandaloneDiffEditor extends DiffEditorWidget implements IStandaloneDiffEditor {
private _contextViewService: IEditorContextViewService;
private _contextViewService: ContextViewService;
private readonly _configurationService: IConfigurationService;
constructor(
domElement: HTMLElement,
@@ -362,8 +371,10 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
@IEditorWorkerService editorWorkerService: IEditorWorkerService,
@ICodeEditorService codeEditorService: ICodeEditorService,
@IStandaloneThemeService themeService: IStandaloneThemeService,
@INotificationService notificationService: INotificationService
@INotificationService notificationService: INotificationService,
@IConfigurationService configurationService: IConfigurationService
) {
applyConfigurationValues(configurationService, options, true);
options = options || {};
if (typeof options.theme === 'string') {
options.theme = themeService.setTheme(options.theme);
@@ -371,7 +382,8 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
super(domElement, options, editorWorkerService, contextKeyService, instantiationService, codeEditorService, themeService, notificationService);
this._contextViewService = <IEditorContextViewService>contextViewService;
this._contextViewService = <ContextViewService>contextViewService;
this._configurationService = configurationService;
this._register(toDispose);
@@ -382,7 +394,12 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
super.dispose();
}
protected _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: IEditorOptions): CodeEditor {
public updateOptions(newOptions: IDiffEditorOptions): void {
applyConfigurationValues(this._configurationService, newOptions, true);
super.updateOptions(newOptions);
}
protected _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: IEditorOptions): CodeEditorWidget {
return instantiationService.createInstance(StandaloneCodeEditor, container, options);
}

View File

@@ -0,0 +1,73 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { IResourceInput } from 'vs/platform/editor/common/editor';
import { TPromise } from 'vs/base/common/winjs.base';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { CodeEditorServiceImpl } from 'vs/editor/browser/services/codeEditorServiceImpl';
import { ScrollType } from 'vs/editor/common/editorCommon';
import { windowOpenNoOpener } from 'vs/base/browser/dom';
import { Schemas } from 'vs/base/common/network';
import { IRange } from 'vs/editor/common/core/range';
import { ITextModel } from 'vs/editor/common/model';
import URI from 'vs/base/common/uri';
export class StandaloneCodeEditorServiceImpl extends CodeEditorServiceImpl {
public getActiveCodeEditor(): ICodeEditor {
return null; // not supported in the standalone case
}
public openCodeEditor(input: IResourceInput, source: ICodeEditor, sideBySide?: boolean): TPromise<ICodeEditor> {
if (!source) {
return TPromise.as(null);
}
return TPromise.as(this.doOpenEditor(source, input));
}
private doOpenEditor(editor: ICodeEditor, input: IResourceInput): ICodeEditor {
const model = this.findModel(editor, input.resource);
if (!model) {
if (input.resource) {
const schema = input.resource.scheme;
if (schema === Schemas.http || schema === Schemas.https) {
// This is a fully qualified http or https URL
windowOpenNoOpener(input.resource.toString());
return editor;
}
}
return null;
}
const selection = <IRange>input.options.selection;
if (selection) {
if (typeof selection.endLineNumber === 'number' && typeof selection.endColumn === 'number') {
editor.setSelection(selection);
editor.revealRangeInCenter(selection, ScrollType.Immediate);
} else {
const pos = {
lineNumber: selection.startLineNumber,
column: selection.startColumn
};
editor.setPosition(pos);
editor.revealPositionInCenter(pos, ScrollType.Immediate);
}
}
return editor;
}
private findModel(editor: ICodeEditor, resource: URI): ITextModel {
const model = editor.getModel();
if (model.uri.toString() !== resource.toString()) {
return null;
}
return model;
}
}

View File

@@ -13,15 +13,14 @@ import { IEditorOverrideServices, DynamicStandaloneServices, StaticServices } fr
import { IDisposable } from 'vs/base/common/lifecycle';
import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { OpenerService } from 'vs/platform/opener/browser/openerService';
import { OpenerService } from 'vs/editor/browser/services/openerService';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { Colorizer, IColorizerElementOptions, IColorizerOptions } from 'vs/editor/standalone/browser/colorizer';
import { SimpleEditorService, SimpleEditorModelResolverService } from 'vs/editor/standalone/browser/simpleServices';
import { SimpleEditorModelResolverService } from 'vs/editor/standalone/browser/simpleServices';
import * as modes from 'vs/editor/common/modes';
import { IWebWorkerOptions, MonacoWebWorker, createWebWorker as actualCreateWebWorker } from 'vs/editor/common/services/webWorker';
import { IMarkerData, IMarker } from 'vs/platform/markers/common/markers';
import { DiffNavigator } from 'vs/editor/browser/widget/diffNavigator';
import { IEditorService } from 'vs/platform/editor/common/editor';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@@ -38,17 +37,11 @@ import * as editorOptions from 'vs/editor/common/config/editorOptions';
import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents';
import { ITextModel, OverviewRulerLane, EndOfLinePreference, DefaultEndOfLine, EndOfLineSequence, TrackedRangeStickiness, TextModelResolvedOptions, FindMatch } from 'vs/editor/common/model';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
function withAllStandaloneServices<T extends editorCommon.IEditor>(domElement: HTMLElement, override: IEditorOverrideServices, callback: (services: DynamicStandaloneServices) => T): T {
let services = new DynamicStandaloneServices(domElement, override);
// The editorService is a lovely beast. It needs to point back to the code editor instance...
let simpleEditorService: SimpleEditorService = null;
if (!services.has(IEditorService)) {
simpleEditorService = new SimpleEditorService();
services.set(IEditorService, simpleEditorService);
}
let simpleEditorModelResolverService: SimpleEditorModelResolverService = null;
if (!services.has(ITextModelService)) {
simpleEditorModelResolverService = new SimpleEditorModelResolverService();
@@ -56,15 +49,11 @@ function withAllStandaloneServices<T extends editorCommon.IEditor>(domElement: H
}
if (!services.has(IOpenerService)) {
services.set(IOpenerService, new OpenerService(services.get(IEditorService), services.get(ICommandService)));
services.set(IOpenerService, new OpenerService(services.get(ICodeEditorService), services.get(ICommandService)));
}
let result = callback(services);
if (simpleEditorService) {
simpleEditorService.setEditor(result);
}
if (simpleEditorModelResolverService) {
simpleEditorModelResolverService.setEditor(result);
}
@@ -90,7 +79,8 @@ export function create(domElement: HTMLElement, options?: IEditorConstructionOpt
services.get(IKeybindingService),
services.get(IContextViewService),
services.get(IStandaloneThemeService),
services.get(INotificationService)
services.get(INotificationService),
services.get(IConfigurationService),
);
});
}
@@ -124,7 +114,8 @@ export function createDiffEditor(domElement: HTMLElement, options?: IDiffEditorC
services.get(IEditorWorkerService),
services.get(ICodeEditorService),
services.get(IStandaloneThemeService),
services.get(INotificationService)
services.get(INotificationService),
services.get(IConfigurationService),
);
});
}
@@ -174,8 +165,8 @@ export function createModel(value: string, language?: string, uri?: URI): ITextM
/**
* Change the language for a model.
*/
export function setModelLanguage(model: ITextModel, language: string): void {
StaticServices.modelService.get().setMode(model, StaticServices.modeService.get().getOrCreateMode(language));
export function setModelLanguage(model: ITextModel, languageId: string): void {
StaticServices.modelService.get().setMode(model, StaticServices.modeService.get().getOrCreateMode(languageId));
}
/**
@@ -271,14 +262,14 @@ export function colorizeModelLine(model: ITextModel, lineNumber: number, tabSize
/**
* @internal
*/
function getSafeTokenizationSupport(languageId: string): modes.ITokenizationSupport {
let tokenizationSupport = modes.TokenizationRegistry.get(languageId);
function getSafeTokenizationSupport(language: string): modes.ITokenizationSupport {
let tokenizationSupport = modes.TokenizationRegistry.get(language);
if (tokenizationSupport) {
return tokenizationSupport;
}
return {
getInitialState: () => NULL_STATE,
tokenize: (line: string, state: modes.IState, deltaOffset: number) => nullTokenize(languageId, line, state, deltaOffset),
tokenize: (line: string, state: modes.IState, deltaOffset: number) => nullTokenize(language, line, state, deltaOffset),
tokenize2: undefined,
};
}
@@ -306,7 +297,7 @@ export function tokenize(text: string, languageId: string): Token[][] {
}
/**
* Define a new theme.
* Define a new theme or updte an existing theme.
*/
export function defineTheme(themeName: string, themeData: IStandaloneThemeData): void {
StaticServices.standaloneThemeService.get().defineTheme(themeName, themeData);
@@ -403,5 +394,6 @@ export function createMonacoEditorAPI(): typeof monaco.editor {
// vars
EditorType: editorCommon.EditorType
};
}

View File

@@ -42,6 +42,11 @@ export function getLanguages(): ILanguageExtensionPoint[] {
return result;
}
export function getEncodedLanguageId(languageId: string): number {
let lid = StaticServices.modeService.get().getLanguageIdentifier(languageId);
return lid && lid.id;
}
/**
* An event emitted when a language is first time needed (e.g. a model has it set).
* @event
@@ -69,6 +74,31 @@ export function setLanguageConfiguration(languageId: string, configuration: Lang
return LanguageConfigurationRegistry.register(languageIdentifier, configuration);
}
/**
* @internal
*/
export class EncodedTokenizationSupport2Adapter implements modes.ITokenizationSupport {
private readonly _actual: EncodedTokensProvider;
constructor(actual: EncodedTokensProvider) {
this._actual = actual;
}
public getInitialState(): modes.IState {
return this._actual.getInitialState();
}
public tokenize(line: string, state: modes.IState, offsetDelta: number): TokenizationResult {
throw new Error('Not supported!');
}
public tokenize2(line: string, state: modes.IState): TokenizationResult2 {
let result = this._actual.tokenizeEncoded(line, state);
return new TokenizationResult2(result.tokens, result.endState);
}
}
/**
* @internal
*/
@@ -203,6 +233,38 @@ export interface ILineTokens {
endState: modes.IState;
}
/**
* The result of a line tokenization.
*/
export interface IEncodedLineTokens {
/**
* The tokens on the line in a binary, encoded format. Each token occupies two array indices. For token i:
* - at offset 2*i => startIndex
* - at offset 2*i + 1 => metadata
* Meta data is in binary format:
* - -------------------------------------------
* 3322 2222 2222 1111 1111 1100 0000 0000
* 1098 7654 3210 9876 5432 1098 7654 3210
* - -------------------------------------------
* bbbb bbbb bfff ffff ffFF FTTT LLLL LLLL
* - -------------------------------------------
* - L = EncodedLanguageId (8 bits): Use `getEncodedLanguageId` to get the encoded ID of a language.
* - T = StandardTokenType (3 bits): Other = 0, Comment = 1, String = 2, RegEx = 4.
* - F = FontStyle (3 bits): None = 0, Italic = 1, Bold = 2, Underline = 4.
* - f = foreground ColorId (9 bits)
* - b = background ColorId (9 bits)
* - The color value for each colorId is defined in IStandaloneThemeData.customTokenColors:
* e.g colorId = 1 is stored in IStandaloneThemeData.customTokenColors[1]. Color id = 0 means no color,
* id = 1 is for the default foreground color, id = 2 for the default background.
*/
tokens: Uint32Array;
/**
* The tokenization end state.
* A pointer will be held to this and the object should not be modified by the tokenizer after the pointer is returned.
*/
endState: modes.IState;
}
/**
* A "manual" provider of tokens.
*/
@@ -217,18 +279,41 @@ export interface TokensProvider {
tokenize(line: string, state: modes.IState): ILineTokens;
}
/**
* A "manual" provider of tokens, returning tokens in a binary form.
*/
export interface EncodedTokensProvider {
/**
* The initial state of a language. Will be the state passed in to tokenize the first line.
*/
getInitialState(): modes.IState;
/**
* Tokenize a line given the state at the beginning of the line.
*/
tokenizeEncoded(line: string, state: modes.IState): IEncodedLineTokens;
}
function isEncodedTokensProvider(provider: TokensProvider | EncodedTokensProvider): provider is EncodedTokensProvider {
return provider['tokenizeEncoded'];
}
/**
* Set the tokens provider for a language (manual implementation).
*/
export function setTokensProvider(languageId: string, provider: TokensProvider): IDisposable {
export function setTokensProvider(languageId: string, provider: TokensProvider | EncodedTokensProvider): IDisposable {
let languageIdentifier = StaticServices.modeService.get().getLanguageIdentifier(languageId);
if (!languageIdentifier) {
throw new Error(`Cannot set tokens provider for unknown language ${languageId}`);
}
let adapter = new TokenizationSupport2Adapter(StaticServices.standaloneThemeService.get(), languageIdentifier, provider);
let adapter: modes.ITokenizationSupport;
if (isEncodedTokensProvider(provider)) {
adapter = new EncodedTokenizationSupport2Adapter(provider);
} else {
adapter = new TokenizationSupport2Adapter(StaticServices.standaloneThemeService.get(), languageIdentifier, provider);
}
return modes.TokenizationRegistry.register(languageId, adapter);
}
/**
* Set the tokens provider for a language (monarch implementation).
*/
@@ -764,6 +849,7 @@ export function createMonacoLanguagesAPI(): typeof monaco.languages {
register: register,
getLanguages: getLanguages,
onLanguage: onLanguage,
getEncodedLanguageId: getEncodedLanguageId,
// provider methods
setLanguageConfiguration: setLanguageConfiguration,
@@ -794,6 +880,7 @@ export function createMonacoLanguagesAPI(): typeof monaco.languages {
SymbolKind: modes.SymbolKind,
IndentAction: IndentAction,
SuggestTriggerKind: modes.SuggestTriggerKind,
CommentThreadCollapsibleState: modes.CommentThreadCollapsibleState,
FoldingRangeKind: modes.FoldingRangeKind
};
}

View File

@@ -29,11 +29,11 @@ import { IModeService } from 'vs/editor/common/services/modeService';
import { ModeServiceImpl } from 'vs/editor/common/services/modeServiceImpl';
import { IModelService } from 'vs/editor/common/services/modelService';
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
import { CodeEditorServiceImpl } from 'vs/editor/browser/services/codeEditorServiceImpl';
import { StandaloneCodeEditorServiceImpl } from 'vs/editor/standalone/browser/standaloneCodeServiceImpl';
import {
SimpleConfigurationService, SimpleResourceConfigurationService, SimpleMenuService,
SimpleProgressService, StandaloneCommandService, StandaloneKeybindingService, SimpleNotificationService,
StandaloneTelemetryService, SimpleWorkspaceContextService, SimpleDialogService
StandaloneTelemetryService, SimpleWorkspaceContextService, SimpleDialogService, SimpleBulkEditService
} from 'vs/editor/standalone/browser/simpleServices';
import { ContextKeyService } from 'vs/platform/contextkey/browser/contextKeyService';
import { IMenuService } from 'vs/platform/actions/common/actions';
@@ -43,11 +43,7 @@ import { ILogService, NullLogService } from 'vs/platform/log/common/log';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IListService, ListService } from 'vs/platform/list/browser/listService';
export interface IEditorContextViewService extends IContextViewService {
dispose(): void;
setContainer(domNode: HTMLElement): void;
}
import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService';
export interface IEditorOverrideServices {
[index: string]: any;
@@ -141,7 +137,7 @@ export module StaticServices {
export const standaloneThemeService = define(IStandaloneThemeService, () => new StandaloneThemeServiceImpl());
export const codeEditorService = define(ICodeEditorService, (o) => new CodeEditorServiceImpl(standaloneThemeService.get(o)));
export const codeEditorService = define(ICodeEditorService, (o) => new StandaloneCodeEditorServiceImpl(standaloneThemeService.get(o)));
export const progressService = define(IProgressService, () => new SimpleProgressService());
@@ -192,6 +188,8 @@ export class DynamicStandaloneServices extends Disposable {
ensure(IContextMenuService, () => this._register(new ContextMenuService(domElement, telemetryService, notificationService, contextViewService)));
ensure(IMenuService, () => new SimpleMenuService(commandService));
ensure(IBulkEditService, () => new SimpleBulkEditService(StaticServices.modelService.get(IModelService)));
}
public get<T>(serviceId: ServiceIdentifier<T>): T {

View File

@@ -5,7 +5,7 @@
'use strict';
import { TokenTheme, ITokenThemeRule, generateTokensCSSForColorMap } from 'vs/editor/common/modes/supports/tokenization';
import { IStandaloneThemeService, BuiltinTheme, IStandaloneThemeData, IStandaloneTheme, IColors } from 'vs/editor/standalone/common/standaloneThemeService';
import { IStandaloneThemeService, BuiltinTheme, IStandaloneThemeData, IStandaloneTheme } from 'vs/editor/standalone/common/standaloneThemeService';
import { vs, vs_dark, hc_black } from 'vs/editor/standalone/common/themes';
import * as dom from 'vs/base/browser/dom';
import { TokenizationRegistry } from 'vs/editor/common/modes';
@@ -14,6 +14,7 @@ import { Extensions, IColorRegistry, ColorIdentifier } from 'vs/platform/theme/c
import { Extensions as ThemingExtensions, IThemingRegistry, ICssStyleCollector } from 'vs/platform/theme/common/themeService';
import { Registry } from 'vs/platform/registry/common/platform';
import { Event, Emitter } from 'vs/base/common/event';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
const VS_THEME_NAME = 'vs';
const VS_DARK_THEME_NAME = 'vs-dark';
@@ -25,13 +26,15 @@ const themingRegistry = Registry.as<IThemingRegistry>(ThemingExtensions.ThemingC
class StandaloneTheme implements IStandaloneTheme {
public readonly id: string;
public readonly themeName: string;
private rules: ITokenThemeRule[];
public readonly base: string;
private themeData: IStandaloneThemeData;
private colors: { [colorId: string]: Color };
private defaultColors: { [colorId: string]: Color };
private _tokenTheme: TokenTheme;
constructor(base: string, name: string, colors: IColors, rules: ITokenThemeRule[]) {
constructor(name: string, standaloneThemeData: IStandaloneThemeData) {
this.themeData = standaloneThemeData;
let base = standaloneThemeData.base;
if (name.length > 0) {
this.id = base + ' ' + name;
this.themeName = name;
@@ -39,18 +42,46 @@ class StandaloneTheme implements IStandaloneTheme {
this.id = base;
this.themeName = base;
}
this.base = base;
this.rules = rules;
this.colors = {};
for (let id in colors) {
this.colors[id] = Color.fromHex(colors[id]);
this.colors = null;
this.defaultColors = Object.create(null);
this._tokenTheme = null;
}
public get base(): string {
return this.themeData.base;
}
public notifyBaseUpdated() {
if (this.themeData.inherit) {
this.colors = null;
this._tokenTheme = null;
}
this.defaultColors = {};
}
private getColors(): { [colorId: string]: Color } {
if (!this.colors) {
let colors: { [colorId: string]: Color } = Object.create(null);
for (let id in this.themeData.colors) {
colors[id] = Color.fromHex(this.themeData.colors[id]);
}
if (this.themeData.inherit) {
let baseData = getBuiltinRules(this.themeData.base);
for (let id in baseData.colors) {
if (!colors[id]) {
colors[id] = Color.fromHex(baseData.colors[id]);
}
}
}
this.colors = colors;
}
return this.colors;
}
public getColor(colorId: ColorIdentifier, useDefault?: boolean): Color {
if (this.colors.hasOwnProperty(colorId)) {
return this.colors[colorId];
const color = this.getColors()[colorId];
if (color) {
return color;
}
if (useDefault !== false) {
return this.getDefault(colorId);
@@ -59,16 +90,17 @@ class StandaloneTheme implements IStandaloneTheme {
}
private getDefault(colorId: ColorIdentifier): Color {
if (this.defaultColors.hasOwnProperty(colorId)) {
return this.defaultColors[colorId];
let color = this.defaultColors[colorId];
if (color) {
return color;
}
let color = colorRegistry.resolveDefaultColor(colorId, this);
color = colorRegistry.resolveDefaultColor(colorId, this);
this.defaultColors[colorId] = color;
return color;
}
public defines(colorId: ColorIdentifier): boolean {
return this.colors.hasOwnProperty(colorId);
return this.getColors().hasOwnProperty(colorId);
}
public get type() {
@@ -81,7 +113,20 @@ class StandaloneTheme implements IStandaloneTheme {
public get tokenTheme(): TokenTheme {
if (!this._tokenTheme) {
this._tokenTheme = TokenTheme.createFromRawTokenTheme(this.rules);
let rules: ITokenThemeRule[] = [];
let encodedTokensColors = [];
if (this.themeData.inherit) {
let baseData = getBuiltinRules(this.themeData.base);
rules = baseData.rules;
if (baseData.encodedTokensColors) {
encodedTokensColors = baseData.encodedTokensColors;
}
}
rules = rules.concat(this.themeData.rules);
if (this.themeData.encodedTokensColors) {
encodedTokensColors = this.themeData.encodedTokensColors;
}
this._tokenTheme = TokenTheme.createFromRawTokenTheme(rules, encodedTokensColors);
}
return this._tokenTheme;
}
@@ -108,7 +153,7 @@ function getBuiltinRules(builtinTheme: BuiltinTheme): IStandaloneThemeData {
function newBuiltInTheme(builtinTheme: BuiltinTheme): StandaloneTheme {
let themeData = getBuiltinRules(builtinTheme);
return new StandaloneTheme(builtinTheme, '', themeData.colors, themeData.rules);
return new StandaloneTheme(builtinTheme, themeData);
}
export class StandaloneThemeServiceImpl implements IStandaloneThemeService {
@@ -119,7 +164,7 @@ export class StandaloneThemeServiceImpl implements IStandaloneThemeService {
private _styleElement: HTMLStyleElement;
private _theme: IStandaloneTheme;
private readonly _onThemeChange: Emitter<IStandaloneTheme>;
private environment: IEnvironmentService = Object.create(null);
constructor() {
this._onThemeChange = new Emitter<IStandaloneTheme>();
@@ -138,28 +183,25 @@ export class StandaloneThemeServiceImpl implements IStandaloneThemeService {
}
public defineTheme(themeName: string, themeData: IStandaloneThemeData): void {
if (!/^[a-z0-9\-]+$/i.test(themeName) || isBuiltinTheme(themeName)) {
if (!/^[a-z0-9\-]+$/i.test(themeName)) {
throw new Error('Illegal theme name!');
}
if (!isBuiltinTheme(themeData.base)) {
if (!isBuiltinTheme(themeData.base) && !isBuiltinTheme(themeName)) {
throw new Error('Illegal theme base!');
}
// set or replace theme
this._knownThemes.set(themeName, new StandaloneTheme(themeName, themeData));
let rules: ITokenThemeRule[] = [];
let colors: IColors = {};
if (themeData.inherit) {
let baseData = getBuiltinRules(themeData.base);
rules = rules.concat(baseData.rules);
for (let id in baseData.colors) {
colors[id] = baseData.colors[id];
}
if (isBuiltinTheme(themeName)) {
this._knownThemes.forEach(theme => {
if (theme.base === themeName) {
theme.notifyBaseUpdated();
}
});
}
rules = rules.concat(themeData.rules);
for (let id in themeData.colors) {
colors[id] = themeData.colors[id];
if (this._theme && this._theme.themeName === themeName) {
this.setTheme(themeName); // refresh theme
}
this._knownThemes.set(themeName, new StandaloneTheme(themeData.base, themeName, colors, rules));
}
public getTheme(): IStandaloneTheme {
@@ -185,7 +227,7 @@ export class StandaloneThemeServiceImpl implements IStandaloneThemeService {
}
}
};
themingRegistry.getThemingParticipants().forEach(p => p(theme, ruleCollector));
themingRegistry.getThemingParticipants().forEach(p => p(theme, ruleCollector, this.environment));
let tokenTheme = theme.tokenTheme;
let colorMap = tokenTheme.getColorMap();