Skip to content

Enhancements to SourceMap decoder from tsserver #28886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Dec 19, 2018
Merged

Conversation

sheetalkamat
Copy link
Member

Current design for creation of source map decoder per project isn't efficient for tsserver. It could be referencing multiple projects for same declaration source map's and each project creates its own source map decoder. Apart from that each source map decoder reads for files and caches them in the decoder for files that aren't present in the program corresponding to the project.

With this approach, it adds a method on LanguageServiceHost as

  • getDocumentPositionMapper: When provided it uses this method to get the document position mapper instead of creating one on its own.
  • getDocumentPositionMapper: When provided it gets the SourceFileLike subset to SourceFile that offers text or optionally methods to map line character to absolute position and other way around. (This helps with us just using snapshots when created to transform these instead of recomputing line starts and doing custom operation.

With this new API, tsserver project now implements these apis to create and cache the Document position mapper on the declaration file's script info. This is maintained till there is change in map file/declaration file. Apart from document position mapper, it maintains the list of source script infos associated with it to update the projects from whenever map file changes.

Apart from this change, it also fixes few existing issues found during additional test writing:

  • File presence detection in the project where the sourceFile(ts file) is assumed to be part of project and its locations are used in generated file (d.ts) file because program.getSourceFile on both path gives the same file (.d.ts).
  • There was also the issue of sourceIndex being compared instead of sourcePosition to sort the sourceMappings based on source location which is fixed in this.
  • Missing path included path for source (.ts) file when the project references the generated file(.d.ts) and file is not found.

Map Info and sources is not ideal and need to revisited since we need to update mapper and projects correctly
// TODO: lifetime of source project and declaration map
@sheetalkamat
Copy link
Member Author

Please review the PR so we can get this in soon.

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

You should get @rbuckton to look over the sourcemap decoder changes, too.

@sheetalkamat
Copy link
Member Author

Ping @rbuckton

@sheetalkamat
Copy link
Member Author

Merging this. Will handle any feedback that @rbuckton provides in separate PR.

@sheetalkamat sheetalkamat merged commit fcd5025 into master Dec 19, 2018
@sheetalkamat sheetalkamat deleted the sourceMapDecoder branch December 19, 2018 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants