提交 9bea4fae 编写于 作者: R Rob Lourens

Remove TPromise from search land #53526

上级 9669edc5
......@@ -35,6 +35,39 @@ export class DeferredTPromise<T> extends TPromise<T> {
}
}
export class DeferredPromise<T> {
private completeCallback: TValueCallback<T>;
private errorCallback: (err: any) => void;
public p: Promise<any>;
constructor() {
this.p = new Promise<any>((c, e) => {
this.completeCallback = c;
this.errorCallback = e;
});
}
public complete(value: T) {
process.nextTick(() => {
this.completeCallback(value);
});
}
public error(err: any) {
process.nextTick(() => {
this.errorCallback(err);
});
}
public cancel() {
process.nextTick(() => {
this.errorCallback(canceled());
});
}
}
export function toResource(this: any, path: string) {
return URI.file(paths.join('C:\\', Buffer.from(this.test.fullTitle()).toString('base64'), path));
}
......
......@@ -5,7 +5,6 @@
import * as nls from 'vs/nls';
import * as errors from 'vs/base/common/errors';
import { TPromise } from 'vs/base/common/winjs.base';
import { URI } from 'vs/base/common/uri';
import * as network from 'vs/base/common/network';
import { Disposable } from 'vs/base/common/lifecycle';
......@@ -47,7 +46,7 @@ export class ReplacePreviewContentProvider implements ITextModelContentProvider,
this.textModelResolverService.registerTextModelContentProvider(network.Schemas.internal, this);
}
public provideTextContent(uri: URI): TPromise<ITextModel> {
public provideTextContent(uri: URI): Thenable<ITextModel> {
if (uri.fragment === REPLACE_PREVIEW) {
return this.instantiationService.createInstance(ReplacePreviewModel).resolve(uri);
}
......@@ -66,7 +65,7 @@ class ReplacePreviewModel extends Disposable {
super();
}
resolve(replacePreviewUri: URI): TPromise<ITextModel> {
resolve(replacePreviewUri: URI): Thenable<ITextModel> {
const fileResource = toFileResource(replacePreviewUri);
const fileMatch = <FileMatch>this.searchWorkbenchService.searchModel.searchResult.matches().filter(match => match.resource().toString() === fileResource.toString())[0];
return this.textModelResolverService.createModelReference(fileResource).then(ref => {
......@@ -101,17 +100,17 @@ export class ReplaceService implements IReplaceService {
@IBulkEditService private bulkEditorService: IBulkEditService
) { }
public replace(match: Match): TPromise<any>;
public replace(files: FileMatch[], progress?: IProgressRunner): TPromise<any>;
public replace(match: FileMatchOrMatch, progress?: IProgressRunner, resource?: URI): TPromise<any>;
public replace(arg: any, progress: IProgressRunner | null = null, resource: URI | null = null): TPromise<any> {
public replace(match: Match): Promise<any>;
public replace(files: FileMatch[], progress?: IProgressRunner): Promise<any>;
public replace(match: FileMatchOrMatch, progress?: IProgressRunner, resource?: URI): Promise<any>;
public replace(arg: any, progress: IProgressRunner | null = null, resource: URI | null = null): Promise<any> {
const edits: ResourceTextEdit[] = this.createEdits(arg, resource);
return this.bulkEditorService.apply({ edits }, { progress }).then(() => this.textFileService.saveAll(edits.map(e => e.resource)));
}
public openReplacePreview(element: FileMatchOrMatch, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): TPromise<any> {
public openReplacePreview(element: FileMatchOrMatch, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): Thenable<any> {
const fileMatch = element instanceof Match ? element.parent() : element;
return this.editorService.openEditor({
......@@ -139,13 +138,13 @@ export class ReplaceService implements IReplaceService {
}, errors.onUnexpectedError);
}
public updateReplacePreview(fileMatch: FileMatch, override: boolean = false): TPromise<void> {
public updateReplacePreview(fileMatch: FileMatch, override: boolean = false): Promise<void> {
const replacePreviewUri = toReplaceResource(fileMatch.resource());
return TPromise.join([this.textModelResolverService.createModelReference(fileMatch.resource()), this.textModelResolverService.createModelReference(replacePreviewUri)])
return Promise.all([this.textModelResolverService.createModelReference(fileMatch.resource()), this.textModelResolverService.createModelReference(replacePreviewUri)])
.then(([sourceModelRef, replaceModelRef]) => {
const sourceModel = sourceModelRef.object.textEditorModel;
const replaceModel = replaceModelRef.object.textEditorModel;
let returnValue = TPromise.wrap(null);
let returnValue = Promise.resolve(null);
// If model is disposed do not update
if (sourceModel && replaceModel) {
if (override) {
......
......@@ -11,7 +11,6 @@ import { normalizeDriveLetter } from 'vs/base/common/labels';
import { Schemas } from 'vs/base/common/network';
import { isWindows, OS } from 'vs/base/common/platform';
import { URI } from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { ITree } from 'vs/base/parts/tree/browser/tree';
import * as nls from 'vs/nls';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
......@@ -45,7 +44,7 @@ export function appendKeyBindingLabel(label: string, keyBinding: number | Resolv
}
}
export function openSearchView(viewletService: IViewletService, panelService: IPanelService, focus?: boolean): TPromise<SearchView> {
export function openSearchView(viewletService: IViewletService, panelService: IPanelService, focus?: boolean): Thenable<SearchView> {
if (viewletService.getViewlets().filter(v => v.id === VIEW_ID).length) {
return viewletService.openViewlet(VIEW_ID, focus).then(viewlet => <SearchView>viewlet);
}
......@@ -97,10 +96,10 @@ export class FocusNextInputAction extends Action {
super(id, label);
}
public run(): TPromise<any> {
public run(): Thenable<any> {
const searchView = getSearchView(this.viewletService, this.panelService);
searchView.focusNextInputBox();
return TPromise.as(null);
return Promise.resolve(null);
}
}
......@@ -115,10 +114,10 @@ export class FocusPreviousInputAction extends Action {
super(id, label);
}
public run(): TPromise<any> {
public run(): Thenable<any> {
const searchView = getSearchView(this.viewletService, this.panelService);
searchView.focusPreviousInputBox();
return TPromise.as(null);
return Promise.resolve(null);
}
}
......@@ -130,7 +129,7 @@ export abstract class FindOrReplaceInFilesAction extends Action {
super(id, label);
}
public run(): TPromise<any> {
public run(): Thenable<any> {
return openSearchView(this.viewletService, this.panelService, false).then(openedView => {
const searchAndReplaceWidget = openedView.searchAndReplaceWidget;
searchAndReplaceWidget.toggleReplace(this.expandSearchReplaceWidget);
......@@ -165,7 +164,7 @@ export class OpenSearchViewletAction extends FindOrReplaceInFilesAction {
super(id, label, viewletService, panelService, /*expandSearchReplaceWidget=*/false);
}
public run(): TPromise<any> {
public run(): Thenable<any> {
// Pass focus to viewlet if not open or focused
if (this.otherViewletShowing() || !isSearchViewFocused(this.viewletService, this.panelService)) {
......@@ -175,7 +174,7 @@ export class OpenSearchViewletAction extends FindOrReplaceInFilesAction {
// Otherwise pass focus to editor group
this.editorGroupService.activeGroup.focus();
return TPromise.as(true);
return Promise.resolve(true);
}
private otherViewletShowing(): boolean {
......@@ -205,11 +204,11 @@ export class CloseReplaceAction extends Action {
super(id, label);
}
public run(): TPromise<any> {
public run(): Thenable<any> {
const searchView = getSearchView(this.viewletService, this.panelService);
searchView.searchAndReplaceWidget.toggleReplace(false);
searchView.searchAndReplaceWidget.focus();
return TPromise.as(null);
return Promise.resolve(null);
}
}
......@@ -231,12 +230,12 @@ export class RefreshAction extends Action {
this.enabled = searchView && searchView.isSearchSubmitted();
}
public run(): TPromise<void> {
public run(): Thenable<void> {
const searchView = getSearchView(this.viewletService, this.panelService);
if (searchView) {
searchView.onQueryChanged();
}
return TPromise.as(null);
return Promise.resolve(null);
}
}
......@@ -258,12 +257,12 @@ export class CollapseDeepestExpandedLevelAction extends Action {
this.enabled = searchView && searchView.hasSearchResults();
}
public run(): TPromise<void> {
public run(): Thenable<void> {
const searchView = getSearchView(this.viewletService, this.panelService);
if (searchView) {
const viewer = searchView.getControl();
if (viewer.getHighlight()) {
return TPromise.as(null); // Global action disabled if user is in edit mode from another action
return Promise.resolve(null); // Global action disabled if user is in edit mode from another action
}
/**
......@@ -299,7 +298,7 @@ export class CollapseDeepestExpandedLevelAction extends Action {
viewer.domFocus();
viewer.focusFirst();
}
return TPromise.as(null);
return Promise.resolve(null);
}
}
......@@ -321,12 +320,12 @@ export class ClearSearchResultsAction extends Action {
this.enabled = searchView && searchView.isSearchSubmitted();
}
public run(): TPromise<void> {
public run(): Thenable<void> {
const searchView = getSearchView(this.viewletService, this.panelService);
if (searchView) {
searchView.clearSearchResults();
}
return TPromise.as(null);
return Promise.resolve(null);
}
}
......@@ -348,13 +347,13 @@ export class CancelSearchAction extends Action {
this.enabled = searchView && searchView.isSearching();
}
public run(): TPromise<void> {
public run(): Thenable<void> {
const searchView = getSearchView(this.viewletService, this.panelService);
if (searchView) {
searchView.cancelSearch();
}
return TPromise.as(null);
return Promise.resolve(null);
}
}
......@@ -369,7 +368,7 @@ export class FocusNextSearchResultAction extends Action {
super(id, label);
}
public run(): TPromise<any> {
public run(): Thenable<any> {
return openSearchView(this.viewletService, this.panelService).then(searchView => {
searchView.selectNextMatch();
});
......@@ -387,7 +386,7 @@ export class FocusPreviousSearchResultAction extends Action {
super(id, label);
}
public run(): TPromise<any> {
public run(): Thenable<any> {
return openSearchView(this.viewletService, this.panelService).then(searchView => {
searchView.selectPreviousMatch();
});
......@@ -470,7 +469,7 @@ export class RemoveAction extends AbstractSearchAndReplaceAction {
super('remove', RemoveAction.LABEL, 'action-remove');
}
public run(): TPromise<any> {
public run(): Thenable<any> {
const currentFocusElement = this.viewer.getFocus();
const nextFocusElement = !currentFocusElement || currentFocusElement instanceof SearchResult || elementIsEqualOrParent(currentFocusElement, this.element) ?
this.getElementToFocusAfterRemoved(this.viewer, this.element) :
......@@ -521,7 +520,7 @@ export class ReplaceAllAction extends AbstractSearchAndReplaceAction {
super(Constants.ReplaceAllInFileActionId, appendKeyBindingLabel(ReplaceAllAction.LABEL, keyBindingService.lookupKeybinding(Constants.ReplaceAllInFileActionId), keyBindingService), 'action-replace-all');
}
public run(): TPromise<any> {
public run(): Thenable<any> {
let nextFocusElement = this.getElementToFocusAfterRemoved(this.viewer, this.fileMatch);
return this.fileMatch.parent().replace(this.fileMatch).then(() => {
if (nextFocusElement) {
......@@ -543,7 +542,7 @@ export class ReplaceAllInFolderAction extends AbstractSearchAndReplaceAction {
super(Constants.ReplaceAllInFolderActionId, appendKeyBindingLabel(ReplaceAllInFolderAction.LABEL, keyBindingService.lookupKeybinding(Constants.ReplaceAllInFolderActionId), keyBindingService), 'action-replace-all');
}
public run(): TPromise<any> {
public run(): Thenable<any> {
let nextFocusElement = this.getElementToFocusAfterRemoved(this.viewer, this.folderMatch);
return this.folderMatch.replaceAll()
.then(() => {
......@@ -567,7 +566,7 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction {
super(Constants.ReplaceActionId, appendKeyBindingLabel(ReplaceAction.LABEL, keyBindingService.lookupKeybinding(Constants.ReplaceActionId), keyBindingService), 'action-replace');
}
public run(): TPromise<any> {
public run(): Thenable<any> {
this.enabled = false;
return this.element.parent().replace(this.element).then(() => {
......
......@@ -10,7 +10,6 @@ import { IAction } from 'vs/base/common/actions';
import { Disposable, dispose, IDisposable } from 'vs/base/common/lifecycle';
import * as paths from 'vs/base/common/paths';
import * as resources from 'vs/base/common/resources';
import { TPromise } from 'vs/base/common/winjs.base';
import { ContextMenuEvent, IAccessibilityProvider, IDataSource, IFilter, IRenderer, ISorter, ITree } from 'vs/base/parts/tree/browser/tree';
import * as nls from 'vs/nls';
import { fillInContextMenuActions } from 'vs/platform/actions/browser/menuItemActionItem';
......@@ -80,15 +79,15 @@ export class SearchDataSource implements IDataSource {
return [];
}
public getChildren(tree: ITree, element: any): TPromise<any[]> {
return TPromise.as(this._getChildren(element));
public getChildren(tree: ITree, element: any): Thenable<any[]> {
return Promise.resolve(this._getChildren(element));
}
public hasChildren(tree: ITree, element: any): boolean {
return element instanceof FileMatch || element instanceof FolderMatch || element instanceof SearchResult;
}
public getParent(tree: ITree, element: any): TPromise<any> {
public getParent(tree: ITree, element: any): Thenable<any> {
let value: any = null;
if (element instanceof Match) {
......@@ -99,7 +98,7 @@ export class SearchDataSource implements IDataSource {
value = element.parent();
}
return TPromise.as(value);
return Promise.resolve(value);
}
public shouldAutoexpand(tree: ITree, element: any): boolean {
......@@ -425,7 +424,7 @@ export class SearchTreeController extends WorkbenchTreeController {
getActions: () => {
const actions: IAction[] = [];
fillInContextMenuActions(this.contextMenu, { shouldForwardArgs: true }, actions, this.contextMenuService);
return actions;
return Promise.resolve(actions);
},
getActionsContext: () => element
......
......@@ -18,7 +18,6 @@ import * as paths from 'vs/base/common/paths';
import * as env from 'vs/base/common/platform';
import * as strings from 'vs/base/common/strings';
import { URI } from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { ITree } from 'vs/base/parts/tree/browser/tree';
import 'vs/css!./media/searchview';
import { ICodeEditor, isCodeEditor, isDiffEditor } from 'vs/editor/browser/editorBrowser';
......@@ -368,23 +367,23 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
this.layout(this.size);
}
private onSearchResultsChanged(event?: IChangeEvent): TPromise<any> {
private onSearchResultsChanged(event?: IChangeEvent): Thenable<any> {
if (this.isVisible()) {
return this.refreshAndUpdateCount(event);
} else {
this.changedWhileHidden = true;
return TPromise.wrap(null);
return Promise.resolve(null);
}
}
private refreshAndUpdateCount(event?: IChangeEvent): TPromise<void> {
private refreshAndUpdateCount(event?: IChangeEvent): Thenable<void> {
return this.refreshTree(event).then(() => {
this.searchWidget.setReplaceAllActionState(!this.viewModel.searchResult.isEmpty());
this.updateSearchResultCount();
});
}
private refreshTree(event?: IChangeEvent): TPromise<any> {
private refreshTree(event?: IChangeEvent): Thenable<any> {
if (!event || event.added || event.removed) {
return this.tree.refresh(this.viewModel.searchResult);
} else {
......@@ -1087,14 +1086,14 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
}, onQueryValidationError);
}
private validateQuery(query: ITextQuery): TPromise<void> {
private validateQuery(query: ITextQuery): Thenable<void> {
// Validate folderQueries
const folderQueriesExistP =
query.folderQueries.map(fq => {
return this.fileService.existsFile(fq.folder);
});
return TPromise.join(folderQueriesExistP).then(existResults => {
return Promise.resolve(folderQueriesExistP).then(existResults => {
// If no folders exist, show an error message about the first one
const existingFolderQueries = query.folderQueries.filter((folderQuery, i) => existResults[i]);
if (!query.folderQueries.length || existingFolderQueries.length) {
......@@ -1102,7 +1101,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
} else {
const nonExistantPath = query.folderQueries[0].folder.fsPath;
const searchPathNotFoundError = nls.localize('searchPathNotFoundError', "Search path not found: {0}", nonExistantPath);
return TPromise.wrapError(new Error(searchPathNotFoundError));
return Promise.reject(new Error(searchPathNotFoundError));
}
return undefined;
......@@ -1349,7 +1348,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
this.openSettings('.exclude');
}
private openSettings(query: string): TPromise<IEditor> {
private openSettings(query: string): Thenable<IEditor> {
const options: ISettingsEditorOptions = { query };
return this.contextService.getWorkbenchState() !== WorkbenchState.EMPTY ?
this.preferencesService.openWorkspaceSettings(undefined, options) :
......@@ -1427,10 +1426,10 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
this.currentSelectedFileMatch = null;
}
private onFocus(lineMatch: any, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): TPromise<any> {
private onFocus(lineMatch: any, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): Thenable<any> {
if (!(lineMatch instanceof Match)) {
this.viewModel.searchResult.rangeHighlightDecorations.removeHighlightRange();
return TPromise.as(true);
return Promise.resolve(true);
}
const useReplacePreview = this.configurationService.getValue<ISearchConfiguration>().search.useReplacePreview;
......@@ -1439,7 +1438,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
this.open(lineMatch, preserveFocus, sideBySide, pinned);
}
public open(element: FileMatchOrMatch, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): TPromise<any> {
public open(element: FileMatchOrMatch, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): Thenable<any> {
const selection = this.getSelectionFrom(element);
const resource = element instanceof Match ? element.parent().resource() : (<FileMatch>element).resource();
return this.editorService.openEditor({
......@@ -1463,7 +1462,7 @@ export class SearchView extends Viewlet implements IViewlet, IPanel {
if (editor) {
return this.editorGroupsService.activateGroup(editor.group);
} else {
return TPromise.wrap(null);
return Promise.resolve(null);
}
}, errors.onUnexpectedError);
}
......
......@@ -17,7 +17,6 @@ import { Emitter, Event } from 'vs/base/common/event';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import * as env from 'vs/base/common/platform';
import * as strings from 'vs/base/common/strings';
import { TPromise } from 'vs/base/common/winjs.base';
import { CONTEXT_FIND_WIDGET_NOT_VISIBLE } from 'vs/editor/contrib/find/findModel';
import * as nls from 'vs/nls';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
......@@ -67,11 +66,11 @@ class ReplaceAllAction extends Action {
this._searchWidget = searchWidget;
}
run(): TPromise<any> {
run(): Promise<any> {
if (this._searchWidget) {
return this._searchWidget.triggerReplaceAll();
}
return TPromise.as(null);
return Promise.resolve(null);
}
}
......@@ -349,9 +348,9 @@ export class SearchWidget extends Widget {
this._register(this.replaceInputFocusTracker.onDidBlur(() => this.replaceInputBoxFocused.set(false)));
}
triggerReplaceAll(): TPromise<any> {
triggerReplaceAll(): Promise<any> {
this._onReplaceAll.fire();
return TPromise.as(null);
return Promise.resolve(null);
}
private onToggleReplaceButton(): void {
......
......@@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { TPromise } from 'vs/base/common/winjs.base';
import { Match, FileMatch, FileMatchOrMatch } from 'vs/workbench/parts/search/common/searchModel';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IProgressRunner } from 'vs/platform/progress/common/progress';
......@@ -17,22 +16,22 @@ export interface IReplaceService {
/**
* Replaces the given match in the file that match belongs to
*/
replace(match: Match): TPromise<any>;
replace(match: Match): Thenable<any>;
/**
* Replace all the matches from the given file matches in the files
* You can also pass the progress runner to update the progress of replacing.
*/
replace(files: FileMatch[], progress?: IProgressRunner): TPromise<any>;
replace(files: FileMatch[], progress?: IProgressRunner): Thenable<any>;
/**
* Opens the replace preview for given file match or match
*/
openReplacePreview(element: FileMatchOrMatch, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): TPromise<any>;
openReplacePreview(element: FileMatchOrMatch, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): Thenable<any>;
/**
* Update the replace preview for the given file.
* If `override` is `true`, then replace preview is constructed from source model
*/
updateReplacePreview(file: FileMatch, override?: boolean): TPromise<void>;
updateReplacePreview(file: FileMatch, override?: boolean): Thenable<void>;
}
......@@ -13,7 +13,6 @@ import { ResourceMap, TernarySearchTree, values } from 'vs/base/common/map';
import * as objects from 'vs/base/common/objects';
import { lcut } from 'vs/base/common/strings';
import { URI } from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { Range } from 'vs/editor/common/core/range';
import { FindMatch, IModelDeltaDecoration, ITextModel, OverviewRulerLane, TrackedRangeStickiness } from 'vs/editor/common/model';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
......@@ -293,7 +292,7 @@ export class FileMatch extends Disposable {
this._onChange.fire(false);
}
public replace(toReplace: Match): TPromise<void> {
public replace(toReplace: Match): Thenable<void> {
return this.replaceService.replace(toReplace)
.then(() => this.updatesMatchesForLineAfterReplace(toReplace.range().startLineNumber, false));
}
......@@ -455,13 +454,13 @@ export class FolderMatch extends Disposable {
this.doRemove(match);
}
public replace(match: FileMatch): TPromise<any> {
public replace(match: FileMatch): Thenable<any> {
return this.replaceService.replace([match]).then(() => {
this.doRemove(match, false, true);
});
}
public replaceAll(): TPromise<any> {
public replaceAll(): Thenable<any> {
const matches = this.matches();
return this.replaceService.replace(matches).then(() => {
matches.forEach(match => this.doRemove(match, false, true));
......@@ -641,11 +640,11 @@ export class SearchResult extends Disposable {
}
}
public replace(match: FileMatch): TPromise<any> {
public replace(match: FileMatch): Thenable<any> {
return this.getFolderMatch(match.resource()).replace(match);
}
public replaceAll(progressRunner: IProgressRunner): TPromise<any> {
public replaceAll(progressRunner: IProgressRunner): Thenable<any> {
this.replacingAll = true;
const promise = this.replaceService.replace(this.matches(), progressRunner);
......@@ -797,7 +796,7 @@ export class SearchModel extends Disposable {
return this._searchResult;
}
public search(query: ITextQuery, onProgress?: (result: ISearchProgressItem) => void): TPromise<ISearchComplete> {
public search(query: ITextQuery, onProgress?: (result: ISearchProgressItem) => void): Thenable<ISearchComplete> {
this.cancelSearch();
this._searchQuery = query;
......
......@@ -9,7 +9,6 @@ import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { ViewletRegistry, Extensions as ViewletExtensions, ViewletDescriptor } from 'vs/workbench/browser/viewlet';
import { IConfigurationRegistry, Extensions as ConfigurationExtensions, ConfigurationScope } from 'vs/platform/configuration/common/configurationRegistry';
import * as nls from 'vs/nls';
import { TPromise } from 'vs/base/common/winjs.base';
import { Action } from 'vs/base/common/actions';
import * as objects from 'vs/base/common/objects';
import * as platform from 'vs/base/common/platform';
......@@ -430,7 +429,7 @@ class ShowAllSymbolsAction extends Action {
this.enabled = !!this.quickOpenService;
}
public run(context?: any): TPromise<void> {
public run(context?: any): Promise<void> {
let prefix = ShowAllSymbolsAction.ALL_SYMBOLS_PREFIX;
let inputSelection: { start: number; end: number; } = void 0;
......@@ -443,7 +442,7 @@ class ShowAllSymbolsAction extends Action {
this.quickOpenService.show(prefix, { inputSelection });
return TPromise.as(null);
return Promise.resolve(null);
}
}
......
......@@ -5,20 +5,19 @@
import * as assert from 'assert';
import * as sinon from 'sinon';
import { timeout } from 'vs/base/common/async';
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
import { URI } from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { DeferredTPromise } from 'vs/base/test/common/utils';
import { DeferredPromise } from 'vs/base/test/common/utils';
import { Range } from 'vs/editor/common/core/range';
import { IModelService } from 'vs/editor/common/services/modelService';
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { IFileMatch, IFileSearchStats, IFolderQuery, ISearchComplete, ISearchProgressItem, ISearchQuery, ISearchService, ITextSearchMatch, TextSearchMatch, OneLineRange } from 'vs/platform/search/common/search';
import { IFileMatch, IFileSearchStats, IFolderQuery, ISearchComplete, ISearchProgressItem, ISearchQuery, ISearchService, ITextSearchMatch, OneLineRange, TextSearchMatch } from 'vs/platform/search/common/search';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
import { SearchModel } from 'vs/workbench/parts/search/common/searchModel';
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
const nullEvent = new class {
......@@ -71,7 +70,7 @@ suite('SearchModel', () => {
instantiationService.stub(ITelemetryService, NullTelemetryService);
instantiationService.stub(IModelService, stubModelService(instantiationService));
instantiationService.stub(ISearchService, {});
instantiationService.stub(ISearchService, 'textSearch', TPromise.as({ results: [] }));
instantiationService.stub(ISearchService, 'textSearch', Promise.resolve({ results: [] }));
});
teardown(() => {
......@@ -82,8 +81,8 @@ suite('SearchModel', () => {
function searchServiceWithResults(results: IFileMatch[], complete: ISearchComplete | null = null): ISearchService {
return <ISearchService>{
textSearch(query: ISearchQuery, token?: CancellationToken, onProgress?: (result: ISearchProgressItem) => void): TPromise<ISearchComplete> {
return new TPromise(resolve => {
textSearch(query: ISearchQuery, token?: CancellationToken, onProgress?: (result: ISearchProgressItem) => void): Thenable<ISearchComplete> {
return new Promise(resolve => {
process.nextTick(() => {
results.forEach(onProgress);
resolve(complete);
......@@ -95,8 +94,8 @@ suite('SearchModel', () => {
function searchServiceWithError(error: Error): ISearchService {
return <ISearchService>{
textSearch(query: ISearchQuery, token?: CancellationToken, onProgress?: (result: ISearchProgressItem) => void): TPromise<ISearchComplete> {
return new TPromise((resolve, reject) => {
textSearch(query: ISearchQuery, token?: CancellationToken, onProgress?: (result: ISearchProgressItem) => void): Thenable<ISearchComplete> {
return new Promise((resolve, reject) => {
reject(error);
});
}
......@@ -105,12 +104,12 @@ suite('SearchModel', () => {
function canceleableSearchService(tokenSource: CancellationTokenSource): ISearchService {
return <ISearchService>{
textSearch(query: ISearchQuery, token?: CancellationToken, onProgress?: (result: ISearchProgressItem) => void): TPromise<ISearchComplete> {
textSearch(query: ISearchQuery, token?: CancellationToken, onProgress?: (result: ISearchProgressItem) => void): Thenable<ISearchComplete> {
if (token) {
token.onCancellationRequested(() => tokenSource.cancel());
}
return new TPromise(resolve => {
return new Promise(resolve => {
process.nextTick(() => {
resolve(<any>{});
});
......@@ -236,13 +235,13 @@ suite('SearchModel', () => {
let target1 = sinon.stub().returns(nullEvent);
instantiationService.stub(ITelemetryService, 'publicLog', target1);
let promise = new DeferredTPromise<ISearchComplete>();
instantiationService.stub(ISearchService, 'textSearch', promise);
let deferredPromise = new DeferredPromise<ISearchComplete>();
instantiationService.stub(ISearchService, 'textSearch', deferredPromise.p);
let testObject = instantiationService.createInstance(SearchModel);
let result = testObject.search({ contentPattern: { pattern: 'somestring' }, type: 1, folderQueries });
promise.cancel();
deferredPromise.cancel();
return timeout(1).then(() => {
return result.then(() => { }, () => {
......
......@@ -10,7 +10,6 @@ import * as glob from 'vs/base/common/glob';
import * as resources from 'vs/base/common/resources';
import { StopWatch } from 'vs/base/common/stopwatch';
import { URI } from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { IFileMatch, IFileSearchProviderStats, IFolderQuery, ISearchCompleteStats, IFileQuery } from 'vs/platform/search/common/search';
import { QueryGlobTester, resolvePatternsForProvider } from 'vs/workbench/services/search/node/search';
import * as vscode from 'vscode';
......@@ -64,10 +63,10 @@ class FileSearchEngine {
this.activeCancellationTokens = new Set();
}
public search(_onResult: (match: IInternalFileMatch) => void): TPromise<IInternalSearchComplete> {
public search(_onResult: (match: IInternalFileMatch) => void): Promise<IInternalSearchComplete> {
const folderQueries = this.config.folderQueries || [];
return new TPromise((resolve, reject) => {
return new Promise((resolve, reject) => {
const onResult = (match: IInternalFileMatch) => {
this.resultCount++;
_onResult(match);
......@@ -94,7 +93,7 @@ class FileSearchEngine {
}
// For each root folder
TPromise.join(folderQueries.map(fq => {
Promise.all(folderQueries.map(fq => {
return this.searchInFolder(fq, onResult);
})).then(stats => {
resolve({
......@@ -111,9 +110,9 @@ class FileSearchEngine {
});
}
private searchInFolder(fq: IFolderQuery<URI>, onResult: (match: IInternalFileMatch) => void): TPromise<IFileSearchProviderStats | null> {
private searchInFolder(fq: IFolderQuery<URI>, onResult: (match: IInternalFileMatch) => void): Promise<IFileSearchProviderStats | null> {
let cancellation = new CancellationTokenSource();
return new TPromise((resolve, reject) => {
return new Promise((resolve, reject) => {
const options = this.getSearchOptionsForFolder(fq);
const tree = this.initDirectoryTree();
......@@ -121,7 +120,7 @@ class FileSearchEngine {
const noSiblingsClauses = !queryTester.hasSiblingExcludeClauses();
let providerSW: StopWatch;
new TPromise(_resolve => process.nextTick(_resolve))
new Promise(_resolve => process.nextTick(_resolve))
.then(() => {
this.activeCancellationTokens.add(cancellation);
......@@ -287,7 +286,7 @@ export class FileSearchManager {
private static readonly BATCH_SIZE = 512;
fileSearch(config: IFileQuery, provider: vscode.FileSearchProvider, onBatch: (matches: IFileMatch[]) => void, token: CancellationToken): TPromise<ISearchCompleteStats> {
fileSearch(config: IFileQuery, provider: vscode.FileSearchProvider, onBatch: (matches: IFileMatch[]) => void, token: CancellationToken): Promise<ISearchCompleteStats> {
const engine = new FileSearchEngine(config, provider);
let resultCount = 0;
......@@ -323,7 +322,7 @@ export class FileSearchManager {
}
}
private doSearch(engine: FileSearchEngine, batchSize: number, onResultBatch: (matches: IInternalFileMatch[]) => void, token: CancellationToken): TPromise<IInternalSearchComplete> {
private doSearch(engine: FileSearchEngine, batchSize: number, onResultBatch: (matches: IInternalFileMatch[]) => void, token: CancellationToken): Promise<IInternalSearchComplete> {
token.onCancellationRequested(() => {
engine.cancel();
});
......@@ -350,7 +349,7 @@ export class FileSearchManager {
onResultBatch(batch);
}
return TPromise.wrapError(error);
return Promise.reject(error);
});
}
}
......@@ -7,7 +7,6 @@ import * as fs from 'fs';
import * as gracefulFs from 'graceful-fs';
import { onUnexpectedError } from 'vs/base/common/errors';
import * as strings from 'vs/base/common/strings';
import { TPromise } from 'vs/base/common/winjs.base';
import { bomLength, decode, detectEncodingFromBuffer, encodingExists, UTF16be, UTF16le, UTF8, UTF8_with_bom } from 'vs/base/node/encoding';
import { Range } from 'vs/editor/common/core/range';
import { ITextSearchPreviewOptions, TextSearchMatch } from 'vs/platform/search/common/search';
......@@ -32,21 +31,21 @@ function onError(error: any): void {
export class SearchWorker implements ISearchWorker {
private currentSearchEngine: SearchWorkerEngine;
initialize(): TPromise<void> {
initialize(): Promise<void> {
this.currentSearchEngine = new SearchWorkerEngine();
return TPromise.wrap<void>(undefined);
return Promise.resolve<void>(undefined);
}
cancel(): TPromise<void> {
cancel(): Promise<void> {
// Cancel the current search. It will stop searching and close its open files.
if (this.currentSearchEngine) {
this.currentSearchEngine.cancel();
}
return TPromise.wrap<void>(null);
return Promise.resolve<void>(null);
}
search(args: ISearchWorkerSearchArgs): TPromise<ISearchWorkerSearchResult> {
search(args: ISearchWorkerSearchArgs): Promise<ISearchWorkerSearchResult> {
if (!this.currentSearchEngine) {
// Worker timed out during search
this.initialize();
......@@ -66,13 +65,13 @@ const LF = 0x0a;
const CR = 0x0d;
export class SearchWorkerEngine {
private nextSearch = TPromise.wrap(null);
private nextSearch = Promise.resolve(null);
private isCanceled = false;
/**
* Searches some number of the given paths concurrently, and starts searches in other paths when those complete.
*/
searchBatch(args: ISearchWorkerSearchArgs): TPromise<ISearchWorkerSearchResult> {
searchBatch(args: ISearchWorkerSearchArgs): Promise<ISearchWorkerSearchResult> {
const contentPattern = strings.createRegExp(args.pattern.pattern, args.pattern.isRegExp, { matchCase: args.pattern.isCaseSensitive, wholeWord: args.pattern.isWordMatch, multiline: false, global: true });
const fileEncoding = encodingExists(args.fileEncoding) ? args.fileEncoding : UTF8;
return this.nextSearch =
......@@ -80,12 +79,12 @@ export class SearchWorkerEngine {
}
private _searchBatch(args: ISearchWorkerSearchArgs, contentPattern: RegExp, fileEncoding: string): TPromise<ISearchWorkerSearchResult> {
private _searchBatch(args: ISearchWorkerSearchArgs, contentPattern: RegExp, fileEncoding: string): Promise<ISearchWorkerSearchResult> {
if (this.isCanceled) {
return TPromise.wrap<ISearchWorkerSearchResult>(null);
return Promise.resolve<ISearchWorkerSearchResult>(null);
}
return new TPromise<ISearchWorkerSearchResult>(batchDone => {
return new Promise<ISearchWorkerSearchResult>(batchDone => {
const result: ISearchWorkerSearchResult = {
matches: [],
numMatches: 0,
......@@ -93,7 +92,7 @@ export class SearchWorkerEngine {
};
// Search in the given path, and when it's finished, search in the next path in absolutePaths
const startSearchInFile = (absolutePath: string): TPromise<void> => {
const startSearchInFile = (absolutePath: string): Promise<void> => {
return this.searchInFile(absolutePath, contentPattern, fileEncoding, args.maxResults && (args.maxResults - result.numMatches), args.previewOptions).then(fileResult => {
// Finish early if search is canceled
if (this.isCanceled) {
......@@ -113,7 +112,7 @@ export class SearchWorkerEngine {
}, onError);
};
TPromise.join(args.absolutePaths.map(startSearchInFile)).then(() => {
Promise.all(args.absolutePaths.map(startSearchInFile)).then(() => {
batchDone(result);
});
});
......@@ -123,7 +122,7 @@ export class SearchWorkerEngine {
this.isCanceled = true;
}
private searchInFile(absolutePath: string, contentPattern: RegExp, fileEncoding: string, maxResults?: number, previewOptions?: ITextSearchPreviewOptions): TPromise<IFileSearchResult> {
private searchInFile(absolutePath: string, contentPattern: RegExp, fileEncoding: string, maxResults?: number, previewOptions?: ITextSearchPreviewOptions): Promise<IFileSearchResult> {
let fileMatch: FileMatch | null = null;
let limitReached = false;
let numMatches = 0;
......@@ -154,8 +153,8 @@ export class SearchWorkerEngine {
() => fileMatch ? { match: fileMatch, limitReached, numMatches } : null);
}
private readlinesAsync(filename: string, perLineCallback: (line: string, lineNumber: number) => void, options: ReadLinesOptions): TPromise<void> {
return new TPromise<void>((resolve, reject) => {
private readlinesAsync(filename: string, perLineCallback: (line: string, lineNumber: number) => void, options: ReadLinesOptions): Promise<void> {
return new Promise<void>((resolve, reject) => {
fs.open(filename, 'r', null, (error: Error, fd: number) => {
if (error) {
return resolve(null);
......
......@@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { TPromise } from 'vs/base/common/winjs.base';
import { IChannel } from 'vs/base/parts/ipc/node/ipc';
import { IPatternInfo, ITextSearchPreviewOptions } from 'vs/platform/search/common/search';
import { SearchWorker } from './searchWorker';
......@@ -25,16 +24,16 @@ export interface ISearchWorkerSearchResult {
}
export interface ISearchWorker {
initialize(): TPromise<void>;
search(args: ISearchWorkerSearchArgs): TPromise<ISearchWorkerSearchResult>;
cancel(): TPromise<void>;
initialize(): Promise<void>;
search(args: ISearchWorkerSearchArgs): Promise<ISearchWorkerSearchResult>;
cancel(): Promise<void>;
}
export interface ISearchWorkerChannel extends IChannel {
call(command: 'initialize'): TPromise<void>;
call(command: 'search', args: ISearchWorkerSearchArgs): TPromise<ISearchWorkerSearchResult>;
call(command: 'cancel'): TPromise<void>;
call(command: string, arg?: any): TPromise<any>;
call(command: 'initialize'): Promise<void>;
call(command: 'search', args: ISearchWorkerSearchArgs): Promise<ISearchWorkerSearchResult>;
call(command: 'cancel'): Promise<void>;
call(command: string, arg?: any): Promise<any>;
}
export class SearchWorkerChannel implements ISearchWorkerChannel {
......@@ -45,7 +44,7 @@ export class SearchWorkerChannel implements ISearchWorkerChannel {
throw new Error('No events');
}
call(command: string, arg?: any): TPromise<any> {
call(command: string, arg?: any): Promise<any> {
switch (command) {
case 'initialize': return this.worker.initialize();
case 'search': return this.worker.search(arg);
......@@ -58,15 +57,15 @@ export class SearchWorkerChannel implements ISearchWorkerChannel {
export class SearchWorkerChannelClient implements ISearchWorker {
constructor(private channel: ISearchWorkerChannel) { }
initialize(): TPromise<void> {
initialize(): Promise<void> {
return this.channel.call('initialize');
}
search(args: ISearchWorkerSearchArgs): TPromise<ISearchWorkerSearchResult> {
search(args: ISearchWorkerSearchArgs): Promise<ISearchWorkerSearchResult> {
return this.channel.call('search', args);
}
cancel(): TPromise<void> {
cancel(): Promise<void> {
return this.channel.call('cancel');
}
}
......@@ -66,12 +66,9 @@ export class TextSearchManager {
type: 'textSearchProvider'
}
});
}, (errs: Error[]) => {
}, (err: Error) => {
tokenSource.dispose();
const errMsg = errs
.map(err => toErrorMessage(err))
.filter(msg => !!msg)[0];
const errMsg = toErrorMessage(err);
reject(new Error(errMsg));
});
});
......
......@@ -9,7 +9,6 @@ import { getPathFromAmdModule } from 'vs/base/common/amd';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import * as glob from 'vs/base/common/glob';
import { URI } from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { IFolderQuery, ISearchRange, ITextQuery, ITextSearchMatch, QueryType, ITextSearchContext, deserializeSearchError, SearchErrorCode } from 'vs/platform/search/common/search';
import { LegacyTextSearchService } from 'vs/workbench/services/search/node/legacy/rawLegacyTextSearchService';
import { ISerializedFileMatch } from 'vs/workbench/services/search/node/search';
......@@ -32,7 +31,7 @@ const MULTIROOT_QUERIES: IFolderQuery[] = [
{ folder: URI.file(MORE_FIXTURES) }
];
function doLegacySearchTest(config: ITextQuery, expectedResultCount: number | Function): TPromise<void> {
function doLegacySearchTest(config: ITextQuery, expectedResultCount: number | Function): Promise<void> {
const engine = new LegacyTextSearchService();
let c = 0;
......@@ -49,7 +48,7 @@ function doLegacySearchTest(config: ITextQuery, expectedResultCount: number | Fu
});
}
function doRipgrepSearchTest(query: ITextQuery, expectedResultCount: number | Function): TPromise<ISerializedFileMatch[]> {
function doRipgrepSearchTest(query: ITextQuery, expectedResultCount: number | Function): Promise<ISerializedFileMatch[]> {
let engine = new TextSearchEngineAdapter(query);
let c = 0;
......
......@@ -690,8 +690,8 @@ suite('ExtHostSearch', () => {
const makeComparable = (results: vscode.TextSearchResult[]) => results
.sort((a, b) => {
const compareKeyA = extensionResultIsMatch(a) ? a.preview.text : a.text;
const compareKeyB = extensionResultIsMatch(b) ? b.preview.text : b.text;
const compareKeyA = a.uri.toString() + ': ' + (extensionResultIsMatch(a) ? a.preview.text : a.text);
const compareKeyB = b.uri.toString() + ': ' + (extensionResultIsMatch(b) ? b.preview.text : b.text);
return compareKeyB.localeCompare(compareKeyA);
})
.map(r => extensionResultIsMatch(r) ? {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册