Skip to content

Break many functions out of services.ts and into their own modules.#10729

Closed
ghost wants to merge 1 commit into
masterfrom
services_modules
Closed

Break many functions out of services.ts and into their own modules.#10729
ghost wants to merge 1 commit into
masterfrom
services_modules

Conversation

@ghost

@ghost ghost commented Sep 6, 2016

Copy link
Copy Markdown

Since many of these functions used to be inside a big closure in services.ts, I've had to add new parameters to many of them.

Note that when moving functions out I often create closure/no-closure pairs.

For example, when extracting out getDocumentHighlights, the new signature has new parameters:

export function getDocumentHighlights(typeChecker: TypeChecker, cancellationToken: CancellationToken, sourceFile: SourceFile, position: number, sourceFilesToSearch: SourceFile[]): DocumentHighlights[] {

So to satisfy the old signatures, we get parameters from the closure and then pass them in.

// Inside closure in services.ts
function getDocumentHighlights(fileName: string, position: number, filesToSearch: string[]): DocumentHighlights[] {
    synchronizeHostData();
    const sourceFilesToSearch = map(filesToSearch, f => program.getSourceFile(f));
    const sourceFile = getValidSourceFile(fileName);
    return DocumentHighlights.getDocumentHighlights(program.getTypeChecker(), cancellationToken, sourceFile, position, sourceFilesToSearch);
}

Here are the changes:

allocators.ts: 625 lines

Exports: getServicesObjectAllocator, a new function I made so that this module would need only 1 export.

classifier.ts: 982 lines

Exports: createClassifier, getSemanticClassifications, getEncodedSemanticClassifications, getSyntacticClassifications, getEncodedSyntacticClassifications

New parameters:

  • checkForClassificationCancellation: cancellationToken
  • getSemanticClassifications: typeChecker, cancellationToken, sourceFile, classifiableNames
  • getEncodedSemanticClassifications: typeChecker, cancellationToken, sourceFile, classifiableNames
  • getSyntacticClassifications: cancellationToken, sourceFile
  • getEncodedSyntacticClassifications: cancellationToken, sourceFile

completions.ts: 1186 lines

Exports: getCompletionsAtPosition, getCompletionEntryDetails

New parameters:

  • getCompletionEntryDisplayNameForSymbol: typeChecker
  • getCompletionEntryDetails: typeChecker, log, target, sourceFile
  • getCompletionsAtPosition: typeChecker, log, target, sourceFile
  • getCompletionData: typeChecker, log, sourceFile

documentHighlights.ts: 638 lines

Exports: getDocumentHighlights

New parameters:

  • getDocumentHighlights: typeChecker, cancellationToken, sourceFile

findAllReferences.ts: 1102 lines

Exports: getReferencedSymbolsForNode

New parameters:

  • getReferencedSymbolsForNode: typeChecker, cancellationToken

goToDefinition.ts: 257 lines

Exports: getDefinitionAtPosition, getTypeDefinitionAtPosition

New parameters:

  • getDefinitionAtPosition: program, sourcefile
    (I didn't want to pass in the whole program, but tryResolveScriptReference requires it and I don't want to do any refactoring in this commit.)
  • createDefinitionFromSignatureDeclaration: typeChecker
  • getDefinitionFromSymbol: typeChecker
  • getTypeDefinitionAtPosition: typeChecker, sourceFile

jsDoc.ts: 403 lines

Exports: getJsDocCommentsFromDeclarations, getAllJsDocCompletionEntries

symbolDisplay.ts: 524 lines

Exports: getSymbolKind, getSymbolModifiers, getSymbolDisplayPartsDocumentationAndSymbolKind

New parameters:

  • getSymbolDisplayPartsDocumentationAndSymbolKind: typeChecker
  • getSymbolKindOfConstructorPropertyMethodAccessorFunctionOrVar: typeChecker
  • getSymbolKind: typeChecker

utilities.ts:

Has 428 lines of new utilities at the top, taken out of services.ts.
I've checked that these are all used in multiple modules (else I would have moved them to the module they are used in).
Breaking the now 1376 lines of utilities apart into logical categories will be a job for another PR.

Other changes

  • Many calls to program.gettypeChecker() have been replaced to just typeChecker parameter accesses. This should have no effect since getTypeChecker only has side effects the first time it is called.
  • Removed BreakContinueSearchType, since that doesn't seem to be used.

}

public getText(sourceFile?: SourceFile): string {
return (sourceFile || this.getSourceFile()).text.substring(this.getStart(), this.getEnd());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass sourceFile into this.getStart()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure to catch sourceFile first.

@zhengbli

zhengbli commented Sep 6, 2016

Copy link
Copy Markdown

Generally looks ok to me. Though I noticed that getReferencesAtPosition and findReferences functions are not put in the findAllReferences.ts file, is it intended?
Also it seems the services.ts is still dividable, for example the navigate-to and navigate-bar related things may be grouped together, and rename, formatting, disgnostics etc. Are those planned or not necessary as for now?

As this is a pretty big change, @mhegazy and @vladima may want to take a look as well.

@ghost

ghost commented Sep 7, 2016

Copy link
Copy Markdown
Author

Closed in favor of #10753.

@ghost ghost closed this Sep 7, 2016
@mhegazy mhegazy deleted the services_modules branch November 2, 2017 21:03
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants