- Notifications
You must be signed in to change notification settings - Fork13.2k
Codebase Services TextChanges
The majority of this file is devoted to a class called theChangeTracker. This class is nearly alwayscreated viaChangeTracker.with where you would give it a context object.
Here is an example context object:
{ cancellationToken:CancellationTokenObject{cancellationToken:TestCancellationToken} errorCode:2304 formatContext:Object{options:Object,getRule:} host:NativeLanguageServiceHost{cancellationToken:TestCancellationToken,settings:Object,sys:System, …} preferences:Object{} program:Object{getRootFileNames:,getSourceFile:,getSourceFileByPath:,…} sourceFile:SourceFileObject{pos:0,end:7,flags:65536, …} span:Object{start:0,length:6}}
You only really seeChangeTrack in use within the codefixes and refactors given that the other case whereTypeScript emits files is a single operation of emission.
The change tracker keeps track of individual changes to be applied to a file. There arecurrently four mainAPIs that it works with:type Change = ReplaceWithSingleNode | ReplaceWithMultipleNodes | RemoveNode | ChangeText;
TheChangeTrack class is then used to provide high level API to describe the sort of changes you might want tomake, which eventually fall into one of the four categories above.
The end result of using aChangeTrack object is an array ofFileTextChanges objects. TheChangeTrack.withfunction lets you work with a tracker instance elsewhere and passes back theChangeTrack objects.
The core work in generating changes occurs in:
Going from an AST node to text is done by creating aprinter ingetNonformattedText. The printerreturns an unformatted node, which is then ran through [a formatter][./formatting.md] and the raw stringsubstitution is done in [applyChanges][9].
Changes look like this:
[{fileName:"/b.js",textChanges:[{span:{start:0,length:0},newText:"// @ts-ignore\n"}]}];
newFileChanges handles passing the set of
News
Debugging TypeScript
- Performance
- Performance-Tracing
- Debugging-Language-Service-in-VS-Code
- Getting-logs-from-TS-Server-in-VS-Code
- JavaScript-Language-Service-in-Visual-Studio
- Providing-Visual-Studio-Repro-Steps
Contributing to TypeScript
- Contributing to TypeScript
- TypeScript Design Goals
- Coding Guidelines
- Useful Links for TypeScript Issue Management
- Writing Good Design Proposals
- Compiler Repo Notes
- Deployment
Building Tools for TypeScript
- Architectural Overview
- Using the Compiler API
- Using the Language Service API
- Standalone Server (tsserver)
- TypeScript MSBuild In Depth
- Debugging Language Service in VS Code
- Writing a Language Service Plugin
- Docker Quickstart
FAQs
The Main Repo