From 5d429192e10ea2cf0b14a418694d8224a905f644 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Mon, 16 Jan 2017 08:38:49 +0100 Subject: [PATCH] debt - fix some layer breakers in workbench --- .../browser/parts/editor/editorStatus.ts | 23 +++---- .../common => common/editor}/indentation.ts | 63 +++++++++++++++++- .../electron-browser/workbench.main.ts | 1 - .../extensions/browser/extensionsActions.ts | 17 ++++- .../extensions.contribution.ts | 2 +- .../indentation/common/indentationCommands.ts | 66 ------------------- .../common/editor/indentation.test.ts} | 2 +- 7 files changed, 86 insertions(+), 88 deletions(-) rename src/vs/workbench/{parts/indentation/common => common/editor}/indentation.ts (68%) delete mode 100644 src/vs/workbench/parts/indentation/common/indentationCommands.ts rename src/vs/workbench/{parts/indentation/test/common/indentationCommands.test.ts => test/common/editor/indentation.test.ts} (98%) diff --git a/src/vs/workbench/browser/parts/editor/editorStatus.ts b/src/vs/workbench/browser/parts/editor/editorStatus.ts index 22d7e8220ce..35120922f07 100644 --- a/src/vs/workbench/browser/parts/editor/editorStatus.ts +++ b/src/vs/workbench/browser/parts/editor/editorStatus.ts @@ -27,7 +27,7 @@ import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/ import { IEditorAction, ICommonCodeEditor, IModelContentChangedEvent, IModelOptionsChangedEvent, IModelLanguageChangedEvent, ICursorPositionChangedEvent, EndOfLineSequence, EditorType, IModel, IDiffEditorModel, IEditor } from 'vs/editor/common/editorCommon'; import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser'; import { TrimTrailingWhitespaceAction } from 'vs/editor/contrib/linesOperations/common/linesOperations'; -import { IndentUsingSpaces, IndentUsingTabs, DetectIndentation, IndentationToSpacesAction, IndentationToTabsAction } from 'vs/workbench/parts/indentation/common/indentation'; +import { IndentUsingSpaces, IndentUsingTabs, DetectIndentation, IndentationToSpacesAction, IndentationToTabsAction } from 'vs/workbench/common/editor/indentation'; import { BaseBinaryResourceEditor } from 'vs/workbench/browser/parts/editor/binaryEditor'; import { BinaryResourceDiffEditor } from 'vs/workbench/browser/parts/editor/binaryDiffEditor'; import { IEditor as IBaseEditor, IEditorInput } from 'vs/platform/editor/common/editor'; @@ -42,10 +42,9 @@ import { StyleMutator } from 'vs/base/browser/styleMutator'; import { Selection } from 'vs/editor/common/core/selection'; import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService'; import { TabFocus } from 'vs/editor/common/config/commonEditorConfig'; -import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; +import { ICommandService } from 'vs/platform/commands/common/commands'; import { IExtensionGalleryService } from 'vs/platform/extensionManagement/common/extensionManagement'; -import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; -import { IExtensionsViewlet, VIEWLET_ID } from 'vs/workbench/parts/extensions/common/extensions'; +import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { getCodeEditor as getEditorWidget } from 'vs/editor/common/services/codeEditorService'; function getCodeEditor(editorWidget: IEditor): ICommonCodeEditor { @@ -680,24 +679,20 @@ function isWritableCodeEditor(e: IBaseEditor): boolean { export class ShowLanguageExtensionsAction extends Action { - static ID = 'workbench.extensions.action.showLanguageExtensions'; + static ID = 'workbench.action.showLanguageExtensions'; constructor( - private extension: string, - @IViewletService private viewletService: IViewletService, + private fileExtension: string, + @ICommandService private commandService: ICommandService, @IExtensionGalleryService galleryService: IExtensionGalleryService ) { - super(ShowLanguageExtensionsAction.ID, nls.localize('showLanguageExtensions', "Search Marketplace Extensions for '{0}'...", extension), null, true); + super(ShowLanguageExtensionsAction.ID, nls.localize('showLanguageExtensions', "Search Marketplace Extensions for '{0}'...", fileExtension)); + this.enabled = galleryService.isEnabled(); } run(): TPromise { - return this.viewletService.openViewlet(VIEWLET_ID, true) - .then(viewlet => viewlet as IExtensionsViewlet) - .then(viewlet => { - viewlet.search(`ext:${this.extension.replace(/^\./, '')}`); - viewlet.focus(); - }); + return this.commandService.executeCommand('workbench.extensions.action.showLanguageExtensions', this.fileExtension).then(() => void 0); } } diff --git a/src/vs/workbench/parts/indentation/common/indentation.ts b/src/vs/workbench/common/editor/indentation.ts similarity index 68% rename from src/vs/workbench/parts/indentation/common/indentation.ts rename to src/vs/workbench/common/editor/indentation.ts index 2f95969bcf4..607df8c965d 100644 --- a/src/vs/workbench/parts/indentation/common/indentation.ts +++ b/src/vs/workbench/common/editor/indentation.ts @@ -5,11 +5,12 @@ import * as nls from 'vs/nls'; import { TPromise } from 'vs/base/common/winjs.base'; -import { ICommonCodeEditor, EditorContextKeys } from 'vs/editor/common/editorCommon'; +import { ICommonCodeEditor, EditorContextKeys, ICommand, ICursorStateComputerData, IEditOperationBuilder, ITokenizedModel } from 'vs/editor/common/editorCommon'; import { editorAction, ServicesAccessor, IActionOptions, EditorAction } from 'vs/editor/common/editorCommonExtensions'; -import { IndentationToSpacesCommand, IndentationToTabsCommand } from 'vs/workbench/parts/indentation/common/indentationCommands'; import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen'; import { IModelService } from 'vs/editor/common/services/modelService'; +import { Range } from 'vs/editor/common/core/range'; +import { Selection } from 'vs/editor/common/core/selection'; @editorAction export class IndentationToSpacesAction extends EditorAction { @@ -160,3 +161,61 @@ export class DetectIndentation extends EditorAction { model.detectIndentation(creationOpts.insertSpaces, creationOpts.tabSize); } } + +function getIndentationEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder, tabSize: number, tabsToSpaces: boolean): void { + if (model.getLineCount() === 1 && model.getLineMaxColumn(1) === 1) { + // Model is empty + return; + } + + let spaces = ''; + for (let i = 0; i < tabSize; i++) { + spaces += ' '; + } + + const content = model.getLinesContent(); + for (let i = 0; i < content.length; i++) { + let lastIndentationColumn = model.getLineFirstNonWhitespaceColumn(i + 1); + if (lastIndentationColumn === 0) { + lastIndentationColumn = model.getLineMaxColumn(i + 1); + } + + const text = (tabsToSpaces ? content[i].substr(0, lastIndentationColumn).replace(/\t/ig, spaces) : + content[i].substr(0, lastIndentationColumn).replace(new RegExp(spaces, 'gi'), '\t')) + + content[i].substr(lastIndentationColumn); + + builder.addEditOperation(new Range(i + 1, 1, i + 1, model.getLineMaxColumn(i + 1)), text); + } +} + +export class IndentationToSpacesCommand implements ICommand { + + private selectionId: string; + + constructor(private selection: Selection, private tabSize: number) { } + + public getEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder): void { + this.selectionId = builder.trackSelection(this.selection); + getIndentationEditOperations(model, builder, this.tabSize, true); + } + + public computeCursorState(model: ITokenizedModel, helper: ICursorStateComputerData): Selection { + return helper.getTrackedSelection(this.selectionId); + } +} + +export class IndentationToTabsCommand implements ICommand { + + private selectionId: string; + + constructor(private selection: Selection, private tabSize: number) { } + + public getEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder): void { + this.selectionId = builder.trackSelection(this.selection); + getIndentationEditOperations(model, builder, this.tabSize, false); + } + + public computeCursorState(model: ITokenizedModel, helper: ICursorStateComputerData): Selection { + return helper.getTrackedSelection(this.selectionId); + } +} diff --git a/src/vs/workbench/electron-browser/workbench.main.ts b/src/vs/workbench/electron-browser/workbench.main.ts index f0752a06f23..3a05b940fe1 100644 --- a/src/vs/workbench/electron-browser/workbench.main.ts +++ b/src/vs/workbench/electron-browser/workbench.main.ts @@ -81,7 +81,6 @@ import 'vs/workbench/parts/emmet/browser/emmet.browser.contribution'; import 'vs/workbench/parts/emmet/node/emmet.contribution'; // Code Editor enhacements -import 'vs/workbench/parts/indentation/common/indentation'; import 'vs/workbench/parts/codeEditor/codeEditor.contribution'; import 'vs/workbench/parts/execution/electron-browser/execution.contribution'; diff --git a/src/vs/workbench/parts/extensions/browser/extensionsActions.ts b/src/vs/workbench/parts/extensions/browser/extensionsActions.ts index eba4ecb0047..e9280041341 100644 --- a/src/vs/workbench/parts/extensions/browser/extensionsActions.ts +++ b/src/vs/workbench/parts/extensions/browser/extensionsActions.ts @@ -18,7 +18,7 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { IExtension, ExtensionState, IExtensionsWorkbenchService, VIEWLET_ID, IExtensionsViewlet } from 'vs/workbench/parts/extensions/common/extensions'; import { ExtensionsConfigurationInitialContent } from 'vs/workbench/parts/extensions/common/extensionsFileTemplate'; import { LocalExtensionType, IExtensionEnablementService } from 'vs/platform/extensionManagement/common/extensionManagement'; -import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; +import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { IMessageService } from 'vs/platform/message/common/message'; import { ToggleViewletAction } from 'vs/workbench/browser/viewlet'; import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet'; @@ -29,7 +29,7 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace import { IWindowService } from 'vs/platform/windows/common/windows'; import { IExtensionService, IExtensionDescription } from 'vs/platform/extensions/common/extensions'; import URI from 'vs/base/common/uri'; - +import { CommandsRegistry } from 'vs/platform/commands/common/commands'; export class InstallAction extends Action { @@ -1290,4 +1290,15 @@ export class EnableAllWorkpsaceAction extends Action { super.dispose(); this.disposables = dispose(this.disposables); } -} \ No newline at end of file +} + +CommandsRegistry.registerCommand('workbench.extensions.action.showLanguageExtensions', function (accessor: ServicesAccessor, fileExtension: string) { + const viewletService = accessor.get(IViewletService); + + return viewletService.openViewlet(VIEWLET_ID, true) + .then(viewlet => viewlet as IExtensionsViewlet) + .then(viewlet => { + viewlet.search(`ext:${fileExtension.replace(/^\./, '')}`); + viewlet.focus(); + }); +}); diff --git a/src/vs/workbench/parts/extensions/electron-browser/extensions.contribution.ts b/src/vs/workbench/parts/extensions/electron-browser/extensions.contribution.ts index e0ea965c2dd..2dd869dcd19 100644 --- a/src/vs/workbench/parts/extensions/electron-browser/extensions.contribution.ts +++ b/src/vs/workbench/parts/extensions/electron-browser/extensions.contribution.ts @@ -149,7 +149,7 @@ const enableAllWorkspaceAction = new SyncActionDescriptor(EnableAllWorkpsaceActi actionRegistry.registerWorkbenchAction(enableAllWorkspaceAction, 'Extensions: Enable All (Workspace)', ExtensionsLabel); const checkForUpdatesAction = new SyncActionDescriptor(CheckForUpdatesAction, CheckForUpdatesAction.ID, CheckForUpdatesAction.LABEL); -actionRegistry.registerWorkbenchAction(checkForUpdatesAction, `Extensions: ${CheckForUpdatesAction.LABEL}`, ExtensionsLabel); +actionRegistry.registerWorkbenchAction(checkForUpdatesAction, `Extensions: Check for Updates`, ExtensionsLabel); Registry.as(ConfigurationExtensions.Configuration) .registerConfiguration({ diff --git a/src/vs/workbench/parts/indentation/common/indentationCommands.ts b/src/vs/workbench/parts/indentation/common/indentationCommands.ts deleted file mode 100644 index 4c2d164fc66..00000000000 --- a/src/vs/workbench/parts/indentation/common/indentationCommands.ts +++ /dev/null @@ -1,66 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { Range } from 'vs/editor/common/core/range'; -import { ICommand, ICursorStateComputerData, IEditOperationBuilder, ITokenizedModel } from 'vs/editor/common/editorCommon'; -import { Selection } from 'vs/editor/common/core/selection'; - -function getIndentationEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder, tabSize: number, tabsToSpaces: boolean): void { - if (model.getLineCount() === 1 && model.getLineMaxColumn(1) === 1) { - // Model is empty - return; - } - - let spaces = ''; - for (let i = 0; i < tabSize; i++) { - spaces += ' '; - } - - const content = model.getLinesContent(); - for (let i = 0; i < content.length; i++) { - let lastIndentationColumn = model.getLineFirstNonWhitespaceColumn(i + 1); - if (lastIndentationColumn === 0) { - lastIndentationColumn = model.getLineMaxColumn(i + 1); - } - - const text = (tabsToSpaces ? content[i].substr(0, lastIndentationColumn).replace(/\t/ig, spaces) : - content[i].substr(0, lastIndentationColumn).replace(new RegExp(spaces, 'gi'), '\t')) + - content[i].substr(lastIndentationColumn); - - builder.addEditOperation(new Range(i + 1, 1, i + 1, model.getLineMaxColumn(i + 1)), text); - } -} - -export class IndentationToSpacesCommand implements ICommand { - - private selectionId: string; - - constructor(private selection: Selection, private tabSize: number) { } - - public getEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder): void { - this.selectionId = builder.trackSelection(this.selection); - getIndentationEditOperations(model, builder, this.tabSize, true); - } - - public computeCursorState(model: ITokenizedModel, helper: ICursorStateComputerData): Selection { - return helper.getTrackedSelection(this.selectionId); - } -} - -export class IndentationToTabsCommand implements ICommand { - - private selectionId: string; - - constructor(private selection: Selection, private tabSize: number) { } - - public getEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder): void { - this.selectionId = builder.trackSelection(this.selection); - getIndentationEditOperations(model, builder, this.tabSize, false); - } - - public computeCursorState(model: ITokenizedModel, helper: ICursorStateComputerData): Selection { - return helper.getTrackedSelection(this.selectionId); - } -} diff --git a/src/vs/workbench/parts/indentation/test/common/indentationCommands.test.ts b/src/vs/workbench/test/common/editor/indentation.test.ts similarity index 98% rename from src/vs/workbench/parts/indentation/test/common/indentationCommands.test.ts rename to src/vs/workbench/test/common/editor/indentation.test.ts index d3d3c6951f6..397af6513ad 100644 --- a/src/vs/workbench/parts/indentation/test/common/indentationCommands.test.ts +++ b/src/vs/workbench/test/common/editor/indentation.test.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { Selection } from 'vs/editor/common/core/selection'; -import { IndentationToSpacesCommand, IndentationToTabsCommand } from 'vs/workbench/parts/indentation/common/indentationCommands'; +import { IndentationToSpacesCommand, IndentationToTabsCommand } from 'vs/workbench/common/editor/indentation'; import { testCommand } from 'vs/editor/test/common/commands/commandTestUtils'; function testIndentationToSpacesCommand(lines: string[], selection: Selection, tabSize: number, expectedLines: string[], expectedSelection: Selection): void { -- GitLab