Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengbli committed Apr 4, 2017
1 parent 0f8ac80 commit fcdbd06
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
5 changes: 5 additions & 0 deletions src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,11 @@ namespace ts.server.protocol {
* Documentation strings for the symbol.
*/
documentation: SymbolDisplayPart[];

/**
* The associated code actions for this entry
*/
codeActions?: CodeAction[];
}

export interface CompletionsResponse extends Response {
Expand Down
14 changes: 4 additions & 10 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ namespace ts.server {
/* @internal */
export const CompletionsFull: protocol.CommandTypes.CompletionsFull = "completions-full";
export const CompletionDetails: protocol.CommandTypes.CompletionDetails = "completionEntryDetails";
export const CommitCompletionWithCodeAction: protocol.CommandTypes.CommitCompletionWithCodeAction = "commitCompletionWithCodeAction";
export const CompileOnSaveAffectedFileList: protocol.CommandTypes.CompileOnSaveAffectedFileList = "compileOnSaveAffectedFileList";
export const CompileOnSaveEmitFile: protocol.CommandTypes.CompileOnSaveEmitFile = "compileOnSaveEmitFile";
export const Configure: protocol.CommandTypes.Configure = "configure";
Expand Down Expand Up @@ -1168,8 +1167,11 @@ namespace ts.server {

return args.entryNames.reduce((accum: protocol.CompletionEntryDetails[], entryName: string) => {
const details = project.getLanguageService().getCompletionEntryDetails(file, position, entryName);
const mappedCodeActions = map(details.codeActions, action => this.mapCodeAction(action, scriptInfo));
const mappedDetails = details as (CompletionEntryDetails | protocol.CompletionEntryDetails);
mappedDetails.codeActions = mappedCodeActions;
if (details) {
accum.push(details);
accum.push(<protocol.CompletionEntryDetails>mappedDetails);
}
return accum;
}, []);
Expand Down Expand Up @@ -1197,11 +1199,6 @@ namespace ts.server {
return result;
}

private getCodeActionAfterCommittingCompletion(args: protocol.CommitCompletionWithCodeActionRequestArgs) {
const { itemName, sourceFileName } = args;
const { file, project } = this.getFileAndProject(args);
}

private emitFile(args: protocol.CompileOnSaveEmitFileRequestArgs) {
const { file, project } = this.getFileAndProject(args);
if (!project) {
Expand Down Expand Up @@ -1686,9 +1683,6 @@ namespace ts.server {
[CommandNames.CompileOnSaveEmitFile]: (request: protocol.CompileOnSaveEmitFileRequest) => {
return this.requiredResponse(this.emitFile(request.arguments));
},
[CommandNames.CommitCompletionWithCodeAction]: (request: protocol.CommitCompletionWithCodeActionRequest) => {
return this.requiredResponse(this.getCodeActionAfterCommittingCompletion(request.arguments));
},
[CommandNames.SignatureHelp]: (request: protocol.SignatureHelpRequest) => {
return this.requiredResponse(this.getSignatureHelpItems(request.arguments, /*simplifiedResult*/ true));
},
Expand Down
13 changes: 10 additions & 3 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ namespace ts.Completions {
// Compute all the completion symbols again.
const completionData = getCompletionData(typeChecker, log, sourceFile, position, allSourceFiles);
if (completionData) {
const { symbols, location } = completionData;
const { symbols, location, symbolActionMap } = completionData;

// Find the symbol with the matching entry name.
// We don't need to perform character checks here because we're only comparing the
Expand All @@ -297,13 +297,20 @@ namespace ts.Completions {
const symbol = forEach(symbols, s => getCompletionEntryDisplayNameForSymbol(typeChecker, s, compilerOptions.target, /*performCharacterChecks*/ false, location) === entryName ? s : undefined);

if (symbol) {

let codeActions: CodeAction[];
if (symbolActionMap.has(getUniqueSymbolIdAsString(symbol, typeChecker))) {
codeActions = [];
}

const { displayParts, documentation, symbolKind } = SymbolDisplay.getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, location, location, SemanticMeaning.All);
return {
name: entryName,
kindModifiers: SymbolDisplay.getSymbolModifiers(symbol),
kind: symbolKind,
displayParts,
documentation
documentation,
codeActions
};
}
}
Expand Down Expand Up @@ -489,7 +496,7 @@ namespace ts.Completions {
// It has a left-hand side, so we're not in an opening JSX tag.
break;
}
// fall through
// fall through

case SyntaxKind.JsxSelfClosingElement:
case SyntaxKind.JsxElement:
Expand Down
1 change: 1 addition & 0 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ namespace ts {
kindModifiers: string; // see ScriptElementKindModifier, comma separated
displayParts: SymbolDisplayPart[];
documentation: SymbolDisplayPart[];
codeActions?: CodeAction[];
}

export interface OutliningSpan {
Expand Down

0 comments on commit fcdbd06

Please sign in to comment.