Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Conversation

@tomv564
Copy link
Contributor

@tomv564 tomv564 commented Jun 3, 2017

As discussed in #208, TS will publish diagnostics when it receives empty content when importing a module.

Normally, the content is guaranteed to be in place for file src/typescript-service.ts by ensureReferencedFiles, but TS was found to be requesting imports like 'vscode-jsonrpc' even when opening an import-free file like 'src/ast.ts'.

The imports were traced back to compiler-emitted declarations like lib/connection.d.ts which were exposed to TS by ensureBasicFiles.

This PR reduces the adding of declarations to only those matching the project configuration for source files.

Besides fixing the repo in #208, this PR allows the tests in #261 to pass and should improve the startup speed of the service on projects with emitted declarations.

@codecov
Copy link

codecov bot commented Jun 3, 2017

Codecov Report

Merging #284 into master will increase coverage by 0.01%.
The diff coverage is 83.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #284      +/-   ##
==========================================
+ Coverage   58.83%   58.85%   +0.01%     
==========================================
  Files          14       14              
  Lines        2128     2129       +1     
  Branches      351      350       -1     
==========================================
+ Hits         1252     1253       +1     
- Misses        725      726       +1     
+ Partials      151      150       -1
Impacted Files Coverage Δ
src/project-manager.ts 81.57% <83.33%> (+0.39%) ⬆️
src/util.ts 81.55% <0%> (-0.98%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 59eabdf...9cbbcc1. Read the comment docs.

const fileName = uri2path(uri);
if (isGlobalTSFile(fileName) || (!isDependencyFile(fileName) && isDeclarationFile(fileName))) {
if (isGlobalTSFile(fileName) ||
(isDeclarationFile(fileName) && expectedFilePaths.includes(toUnixPath(fileName)))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This excludes non-declaration files in expected files.

Copy link
Contributor

Choose a reason for hiding this comment

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

At first I though this reverted tomv564@021d1b4 but it still looks in this.fs.uris() 👍

  • when adding basic files, search for them project-wide instead of searching in expected files list. The reason is that files may be excluded by tsconfig.json rule

}

// paths have been forward-slashified by TS (see toUnixPath below)
// TODO: consider moving expectedFilePaths out of LanguageServiceHost?
Copy link
Contributor

Choose a reason for hiding this comment

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

Funny, I always thought TS required expectedFilePath to be implemented. Turns out it doesn't and it's not even used inside the class. We can totally move it to ProjectConfiguration.

/**
* List of files that project consist of (based on tsconfig includes/excludes and wildcards).
* Each item is a relative file path
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Make it private please and initialize here instead of in the constructor

@felixfbecker
Copy link
Contributor

Didn't fix #285 unfortunately :(

@felixfbecker
Copy link
Contributor

Is it possible to write a unit test for this?

Keep expectedFilePaths in a Set that is iterated separately.
}
}

// Add files that belong to the project according to tsconfig.json settings
Copy link
Contributor Author

@tomv564 tomv564 Jun 3, 2017

Choose a reason for hiding this comment

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

This changes the previous behaviour of only adding declaration files project-wide and adding regular TS files as-needed. Now there is essentially nothing loaded on-demand anymore, are you sure this is what you want?

Copy link
Contributor

Choose a reason for hiding this comment

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

You are correct, will revert

@tomv564
Copy link
Contributor Author

tomv564 commented Jun 4, 2017

There is likely a bit of set-up effort for a unit test of ensureBasicFiles. Might as well cover all the ensure functions on ProjectConfiguration!

The dependencies are also a bit tricky, e.g. ensureBasicFiles checks with a live ts.Program instance if a source file is available with adding it to the LanguageServiceHost. Would be a faster and tighter test if all the file-loading interaction could be tested with a mocked LanguageServiceHost.

I could look at adding these tests in a couple of days, but I'd love to hear what you think of ProjectConfiguration's testability.

@felixfbecker
Copy link
Contributor

It would be possible to test the methods in ProjectConfiguration by stubbing all dependencies with sinon and asserting calls, but I don't think there would be much value to it, because it would be very easy to write tests that assert wrong behaviour. The way ensureBasicFiles etc work is a performance trade off (adding the minimal amount of files). I think it makes more sense to have tests that ensure specific hovers/j2d in specific workspaces still work, so we can change the implementation as long as these cases work.

@felixfbecker felixfbecker merged commit eff3248 into sourcegraph:master Jun 4, 2017
@tomv564 tomv564 deleted the only-expose-expected-declaration-files branch September 9, 2017 09:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants