Skip to content

Commit

Permalink
Use different names for Options and GetCompletionsAtPositionOptions (…
Browse files Browse the repository at this point in the history
…todo: come up with better names)
  • Loading branch information
Andy Hanson committed Mar 6, 2018
1 parent 4d592ee commit be34eb6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2392,7 +2392,7 @@ Actual: ${stringify(fullActual)}`);
public applyCodeActionFromCompletion(markerName: string, options: FourSlashInterface.VerifyCompletionActionOptions) {
this.goToMarker(markerName);

const actualCompletion = this.getCompletionListAtCaret({ ...ts.defaultOptions, includeExternalModuleExports: true }).entries.find(e =>
const actualCompletion = this.getCompletionListAtCaret({ ...ts.defaultOptions, includeExternalModuleExportsInCompletionList: true }).entries.find(e =>
e.name === options.name && e.source === options.source);

if (!actualCompletion.hasAction) {
Expand Down
6 changes: 3 additions & 3 deletions src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2589,17 +2589,17 @@ namespace ts.server.protocol {
}

export interface Options {
quote?: "double" | "single";
readonly quote?: "double" | "single";
/**
* If enabled, TypeScript will search through all external modules' exports and add them to the completions list.
* This affects lone identifier completions but not completions on the right hand side of `obj.`.
*/
includeExternalModuleExports?: boolean;
readonly includeExternalModuleExportsInCompletionList?: boolean;
/**
* If enabled, the completion list will include completions with invalid identifier names.
* For those entries, The `insertText` and `replacementSpan` properties will be set to change from `.x` property access to `["x"]`.
*/
includeInsertTextCompletions?: boolean;
readonly includeInsertTextCompletionsInCompletionList?: boolean;
}

export interface CompilerOptions {
Expand Down
12 changes: 6 additions & 6 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ namespace ts.Completions {

let insertText: string | undefined;
let replacementSpan: TextSpan | undefined;
if (options.includeInsertTextCompletions) {
if (options.includeInsertTextCompletionsInCompletionList) {
if (origin && origin.type === "this-type") {
insertText = needsConvertPropertyAccess ? `this[${quote(name, options)}]` : `this.${name}`;
}
Expand All @@ -227,7 +227,7 @@ namespace ts.Completions {
}
}

if (insertText !== undefined && !options.includeInsertTextCompletions) {
if (insertText !== undefined && !options.includeInsertTextCompletionsInCompletionList) {
return undefined;
}

Expand Down Expand Up @@ -479,7 +479,7 @@ namespace ts.Completions {
{ name, source }: CompletionEntryIdentifier,
allSourceFiles: ReadonlyArray<SourceFile>,
): SymbolCompletion | { type: "request", request: Request } | { type: "none" } {
const completionData = getCompletionData(typeChecker, log, sourceFile, position, allSourceFiles, { includeExternalModuleExports: true, includeInsertTextCompletions: true }, compilerOptions.target);
const completionData = getCompletionData(typeChecker, log, sourceFile, position, allSourceFiles, { includeExternalModuleExportsInCompletionList: true, includeInsertTextCompletionsInCompletionList: true }, compilerOptions.target);
if (!completionData) {
return { type: "none" };
}
Expand Down Expand Up @@ -746,7 +746,7 @@ namespace ts.Completions {
sourceFile: SourceFile,
position: number,
allSourceFiles: ReadonlyArray<SourceFile>,
options: Pick<Options, "includeExternalModuleExports" | "includeInsertTextCompletions">,
options: Pick<Options, "includeExternalModuleExportsInCompletionList" | "includeInsertTextCompletionsInCompletionList">,
target: ScriptTarget,
): CompletionData | Request | undefined {
let start = timestamp();
Expand Down Expand Up @@ -1150,7 +1150,7 @@ namespace ts.Completions {
symbols = Debug.assertEachDefined(typeChecker.getSymbolsInScope(scopeNode, symbolMeanings), "getSymbolsInScope() should all be defined");

// Need to insert 'this.' before properties of `this` type, so only do that if `includeInsertTextCompletions`
if (options.includeInsertTextCompletions && scopeNode.kind !== SyntaxKind.SourceFile) {
if (options.includeInsertTextCompletionsInCompletionList && scopeNode.kind !== SyntaxKind.SourceFile) {
const thisType = typeChecker.tryGetThisTypeAt(scopeNode);
if (thisType) {
for (const symbol of getPropertiesForCompletion(thisType, typeChecker, /*isForAccess*/ true)) {
Expand All @@ -1160,7 +1160,7 @@ namespace ts.Completions {
}
}

if (options.includeExternalModuleExports) {
if (options.includeExternalModuleExportsInCompletionList) {
getSymbolsFromOtherSourceFileExports(symbols, previousToken && isIdentifier(previousToken) ? previousToken.text : "", target);
}
filterGlobalCompletion(symbols);
Expand Down
22 changes: 14 additions & 8 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

namespace ts {
/** The version of the language service API */
export const servicesVersion = "0.7";
export const servicesVersion = "0.8";

function createNode<TKind extends SyntaxKind>(kind: TKind, pos: number, end: number, parent?: Node): NodeObject | TokenObject<TKind> | IdentifierObject {
const node = isNodeKind(kind) ? new NodeObject(kind, pos, end) :
Expand Down Expand Up @@ -1424,7 +1424,13 @@ namespace ts {
return [...program.getOptionsDiagnostics(cancellationToken), ...program.getGlobalDiagnostics(cancellationToken)];
}

function getCompletionsAtPosition(fileName: string, position: number, settings: Options = defaultOptions): CompletionInfo {
function getCompletionsAtPosition(fileName: string, position: number, options: GetCompletionsAtPositionOptions = defaultOptions): CompletionInfo {
// Convert from deprecated options names to new names
const fullOptions: Options = {
...identity<Options>(options), // avoid excess property check
includeExternalModuleExportsInCompletionList: options.includeExternalModuleExportsInCompletionList || options.includeExternalModuleExports,
includeInsertTextCompletionsInCompletionList: options.includeInsertTextCompletionsInCompletionList || options.includeInsertTextCompletions,
};
synchronizeHostData();
return Completions.getCompletionsAtPosition(
host,
Expand All @@ -1434,7 +1440,7 @@ namespace ts {
getValidSourceFile(fileName),
position,
program.getSourceFiles(),
settings);
fullOptions);
}

function getCompletionEntryDetails(fileName: string, position: number, name: string, formattingOptions?: FormatCodeSettings, source?: string): CompletionEntryDetails {
Expand Down Expand Up @@ -1814,7 +1820,7 @@ namespace ts {
return [];
}

function getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: ReadonlyArray<number>, formatOptions: FormatCodeSettings, options: Options): ReadonlyArray<CodeFixAction> {
function getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: ReadonlyArray<number>, formatOptions: FormatCodeSettings, options: Options = defaultOptions): ReadonlyArray<CodeFixAction> {
synchronizeHostData();
const sourceFile = getValidSourceFile(fileName);
const span = createTextSpanFromBounds(start, end);
Expand All @@ -1826,7 +1832,7 @@ namespace ts {
});
}

function getCombinedCodeFix(scope: CombinedCodeFixScope, fixId: {}, formatOptions: FormatCodeSettings, options: Options): CombinedCodeActions {
function getCombinedCodeFix(scope: CombinedCodeFixScope, fixId: {}, formatOptions: FormatCodeSettings, options: Options = defaultOptions): CombinedCodeActions {
synchronizeHostData();
Debug.assert(scope.type === "file");
const sourceFile = getValidSourceFile(scope.fileName);
Expand All @@ -1835,7 +1841,7 @@ namespace ts {
return codefix.getAllFixes({ fixId, sourceFile, program, host, cancellationToken, formatContext, options });
}

function organizeImports(scope: OrganizeImportsScope, formatOptions: FormatCodeSettings, options: Options): ReadonlyArray<FileTextChanges> {
function organizeImports(scope: OrganizeImportsScope, formatOptions: FormatCodeSettings, options: Options = defaultOptions): ReadonlyArray<FileTextChanges> {
synchronizeHostData();
Debug.assert(scope.type === "file");
const sourceFile = getValidSourceFile(scope.fileName);
Expand Down Expand Up @@ -2079,7 +2085,7 @@ namespace ts {
};
}

function getApplicableRefactors(fileName: string, positionOrRange: number | TextRange, options: Options): ApplicableRefactorInfo[] {
function getApplicableRefactors(fileName: string, positionOrRange: number | TextRange, options: Options = defaultOptions): ApplicableRefactorInfo[] {
synchronizeHostData();
const file = getValidSourceFile(fileName);
return refactor.getApplicableRefactors(getRefactorContext(file, positionOrRange, options));
Expand All @@ -2091,7 +2097,7 @@ namespace ts {
positionOrRange: number | TextRange,
refactorName: string,
actionName: string,
options: Options,
options: Options = defaultOptions,
): RefactorEditInfo {

synchronizeHostData();
Expand Down
19 changes: 12 additions & 7 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ namespace ts {

export interface Options {
readonly quote?: "double" | "single";
readonly includeExternalModuleExports?: boolean;
readonly includeInsertTextCompletions?: boolean;
readonly includeExternalModuleExportsInCompletionList?: boolean;
readonly includeInsertTextCompletionsInCompletionList?: boolean;
}
/* @internal */
export const defaultOptions: Options = {};
Expand Down Expand Up @@ -250,7 +250,7 @@ namespace ts {
getEncodedSyntacticClassifications(fileName: string, span: TextSpan): Classifications;
getEncodedSemanticClassifications(fileName: string, span: TextSpan): Classifications;

getCompletionsAtPosition(fileName: string, position: number, settings: Options | undefined): CompletionInfo;
getCompletionsAtPosition(fileName: string, position: number, options: GetCompletionsAtPositionOptions | undefined): CompletionInfo;
// "options" and "source" are optional only for backwards-compatibility
getCompletionEntryDetails(
fileName: string,
Expand Down Expand Up @@ -314,9 +314,9 @@ namespace ts {
applyCodeActionCommand(fileName: string, action: CodeActionCommand[]): Promise<ApplyCodeActionCommandResult[]>;
/** @deprecated `fileName` will be ignored */
applyCodeActionCommand(fileName: string, action: CodeActionCommand | CodeActionCommand[]): Promise<ApplyCodeActionCommandResult | ApplyCodeActionCommandResult[]>;
getApplicableRefactors(fileName: string, positionOrRaneg: number | TextRange, options: Options): ApplicableRefactorInfo[];
getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, options: Options): RefactorEditInfo | undefined;
organizeImports(scope: OrganizeImportsScope, formatOptions: FormatCodeSettings, options: Options): ReadonlyArray<FileTextChanges>;
getApplicableRefactors(fileName: string, positionOrRaneg: number | TextRange, options: Options | undefined): ApplicableRefactorInfo[];
getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, options: Options | undefined): RefactorEditInfo | undefined;
organizeImports(scope: OrganizeImportsScope, formatOptions: FormatCodeSettings, options: Options | undefined): ReadonlyArray<FileTextChanges>;

getEmitOutput(fileName: string, emitOnlyDtsFiles?: boolean): EmitOutput;

Expand All @@ -338,7 +338,12 @@ namespace ts {
export type OrganizeImportsScope = CombinedCodeFixScope;

/** @deprecated Use Options */
export type GetCompletionsAtPositionOptions = Options;
export interface GetCompletionsAtPositionOptions extends Options {
/** @deprecated Use includeExternalModuleExportsInCompletionList */
includeExternalModuleExports?: boolean;
/** @deprecated Use includeInsertTextCompletionsInCompletionList */
includeInsertTextCompletions?: boolean;
}

export interface ApplyCodeActionCommandResult {
successMessage: string;
Expand Down

0 comments on commit be34eb6

Please sign in to comment.