提交 ec8a02a3 编写于 作者: J Johannes Rieken

debt - remove rename/common

上级 7a4d2a16
......@@ -6,7 +6,7 @@
'use strict';
import * as nls from 'vs/nls';
import { isPromiseCanceledError } from 'vs/base/common/errors';
import { isPromiseCanceledError, onUnexpectedExternalError, illegalArgument } from 'vs/base/common/errors';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import Severity from 'vs/base/common/severity';
import { TPromise } from 'vs/base/common/winjs.base';
......@@ -16,14 +16,65 @@ import { IMessageService } from 'vs/platform/message/common/message';
import { IProgressService } from 'vs/platform/progress/common/progress';
import { editorAction, ServicesAccessor, EditorAction, EditorCommand, CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions';
import { editorContribution } from 'vs/editor/browser/editorBrowserExtensions';
import { IRange, ICommonCodeEditor, EditorContextKeys, ModeContextKeys, IEditorContribution } from 'vs/editor/common/editorCommon';
import { IRange, ICommonCodeEditor, EditorContextKeys, ModeContextKeys, IEditorContribution, IReadOnlyModel } from 'vs/editor/common/editorCommon';
import { BulkEdit, createBulkEdit } from 'vs/editor/common/services/bulkEdit';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { rename } from '../common/rename';
import RenameInputField from './renameInputField';
import { ITextModelResolverService } from 'vs/editor/common/services/resolverService';
import { optional } from 'vs/platform/instantiation/common/instantiation';
import { IThemeService } from "vs/platform/theme/common/themeService";
import { sequence, asWinJsPromise } from 'vs/base/common/async';
import { WorkspaceEdit, RenameProviderRegistry } from 'vs/editor/common/modes';
import { Position } from 'vs/editor/common/core/position';
export function rename(model: IReadOnlyModel, position: Position, newName: string): TPromise<WorkspaceEdit> {
const supports = RenameProviderRegistry.ordered(model);
const rejects: string[] = [];
let hasResult = false;
const factory = supports.map(support => {
return () => {
if (!hasResult) {
return asWinJsPromise((token) => {
return support.provideRenameEdits(model, position, newName, token);
}).then(result => {
if (!result) {
// ignore
} else if (!result.rejectReason) {
hasResult = true;
return result;
} else {
rejects.push(result.rejectReason);
}
return undefined;
}, err => {
onUnexpectedExternalError(err);
return TPromise.wrapError<WorkspaceEdit>('provider failed');
});
}
return undefined;
};
});
return sequence(factory).then((values): WorkspaceEdit => {
let result = values[0];
if (rejects.length > 0) {
return {
edits: undefined,
rejectReason: rejects.join('\n')
};
} else if (!result) {
return {
edits: undefined,
rejectReason: nls.localize('no result', "No result.")
};
} else {
return result;
}
});
}
// --- register actions and commands
......@@ -204,3 +255,13 @@ CommonEditorRegistry.registerEditorCommand(new RenameCommand({
secondary: [KeyMod.Shift | KeyCode.Escape]
}
}));
// ---- api bridge command
CommonEditorRegistry.registerDefaultLanguageCommand('_executeDocumentRenameProvider', function (model, position, args) {
let { newName } = args;
if (typeof newName !== 'string') {
throw illegalArgument('newName');
}
return rename(model, position, newName);
});
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { localize } from 'vs/nls';
import { sequence, asWinJsPromise } from 'vs/base/common/async';
import { illegalArgument, onUnexpectedExternalError } from 'vs/base/common/errors';
import { TPromise } from 'vs/base/common/winjs.base';
import { IReadOnlyModel } from 'vs/editor/common/editorCommon';
import { CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions';
import { WorkspaceEdit, RenameProviderRegistry } from 'vs/editor/common/modes';
import { Position } from 'vs/editor/common/core/position';
export function rename(model: IReadOnlyModel, position: Position, newName: string): TPromise<WorkspaceEdit> {
const supports = RenameProviderRegistry.ordered(model);
const rejects: string[] = [];
let hasResult = false;
const factory = supports.map(support => {
return () => {
if (!hasResult) {
return asWinJsPromise((token) => {
return support.provideRenameEdits(model, position, newName, token);
}).then(result => {
if (!result) {
// ignore
} else if (!result.rejectReason) {
hasResult = true;
return result;
} else {
rejects.push(result.rejectReason);
}
return undefined;
}, err => {
onUnexpectedExternalError(err);
return TPromise.wrapError<WorkspaceEdit>('provider failed');
});
}
return undefined;
};
});
return sequence(factory).then((values): WorkspaceEdit => {
let result = values[0];
if (rejects.length > 0) {
return {
edits: undefined,
rejectReason: rejects.join('\n')
};
} else if (!result) {
return {
edits: undefined,
rejectReason: localize('no result', "No result.")
};
} else {
return result;
}
});
}
CommonEditorRegistry.registerDefaultLanguageCommand('_executeDocumentRenameProvider', function (model, position, args) {
let {newName} = args;
if (typeof newName !== 'string') {
throw illegalArgument('newName');
}
return rename(model, position, newName);
});
......@@ -34,7 +34,7 @@ import { getOccurrencesAtPosition } from 'vs/editor/contrib/wordHighlighter/comm
import { provideReferences } from 'vs/editor/contrib/referenceSearch/common/referenceSearch';
import { getCodeActions } from 'vs/editor/contrib/quickFix/common/quickFix';
import { getWorkspaceSymbols } from 'vs/workbench/parts/search/common/search';
import { rename } from 'vs/editor/contrib/rename/common/rename';
import { rename } from 'vs/editor/contrib/rename/browser/rename';
import { provideSignatureHelp } from 'vs/editor/contrib/parameterHints/common/parameterHints';
import { provideSuggestionItems } from 'vs/editor/contrib/suggest/common/suggest';
import { getDocumentFormattingEdits, getDocumentRangeFormattingEdits, getOnTypeFormattingEdits } from 'vs/editor/contrib/format/common/format';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册