-
-
Notifications
You must be signed in to change notification settings - Fork 208
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
(fix) only allow client files and project files to be root #2146
Conversation
…nto root-files
not sure if it make a huge difference
some tests became flaky because syncing is too eager
f4e7f3a
to
c1ccdf3
Compare
* Retrieves the LS for operations that don't need cross-files information. | ||
* can save some time by not synchronizing languageService program | ||
*/ | ||
async getLsForSyntheticOperations(document: Document): Promise<{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created this as a separate method because it gave it a more meaningful name, so the code intention is clearer. And, well, tsserver also does that😆,
lang: langForSyntheticOperations, | ||
tsDoc, | ||
userPreferences | ||
} = await this.lsAndTsDocResolver.getLsForSyntheticOperations(document); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reuse completion check and JSDoc template both don't need the language service program to be up to date.
@@ -8,16 +8,16 @@ import { LSAndTSDocResolver } from '../../../../src/plugins/typescript/LSAndTSDo | |||
import { pathToUrl } from '../../../../src/utils'; | |||
import { serviceWarmup } from '../test-utils'; | |||
|
|||
const testDir = path.join(__dirname, '..'); | |||
const testDir = path.join(__dirname, '..', 'testfiles'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warms up the wrong directory. I fixed it while debugging why the test is flaky again.
@@ -43,7 +43,7 @@ describe('DiagnosticsProvider', function () { | |||
const newFilePath = normalizePath(path.join(testDir, 'doesntexistyet.js')) || ''; | |||
writeFileSync(newFilePath, 'export default function foo() {}'); | |||
assert.ok(existsSync(newFilePath)); | |||
await lsAndTsDocResolver.getSnapshot(newFilePath); | |||
await lsAndTsDocResolver.invalidateModuleCache(newFilePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is the one that failed because getSnapshot
no longer adds new root files, and it's the reason why I use the internal API hasInvalidatedResolutions
.
} | ||
|
||
languageService.getProgram(); | ||
svelteModuleLoader.clearPendingInvalidations(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wrapper layer is needed because we need to clear the invalidated files so they won't affect every program update check afterwards. And the hoops you have to jump through are probably why hasInvalidatedResolutions
is a TypeScript internal API 😅.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn, impressive work!
To summarize in my own words, to double-check I understood this all correctly:
- we're shifting
openedByClient
elsewhere so that we no longer mark all TS/JS files we pick up along the way as open automatically, because that's wrong - we're now using
openedByClient
to filter the files, which is why we need to be more granular about what is marked as opened in the client - because we're no longer marking every TS/JS file as opened, we have to do some more work in other places to correctly clear the module resolution cache in situations like creation/deletion/move, which is what we need the failed lookup info etc for
- because we have this additional logic now, we can also be more precise about when to invalidate the program (
updateIfDirty
) - as a drive-by, we now optimize a bit with the "get language service but don't sync" bit
My guess is this PR might make things a bit more performant in some cases?
@@ -49,6 +50,7 @@ class ModuleResolutionCache { | |||
this.cache.forEach((val, key) => { | |||
if (val && this.getCanonicalFileName(val.resolvedFileName) === resolvedModuleName) { | |||
this.cache.delete(key); | |||
this.pendingInvalidations.add(key.split(':::').shift() || ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably makes sense to have :::
as const
at the top and use that at this point
@@ -61,16 +63,27 @@ class ModuleResolutionCache { | |||
const fileNameWithoutEnding = | |||
getLastPartOfPath(this.getCanonicalFileName(path)).split('.').shift() || ''; | |||
this.cache.forEach((val, key) => { | |||
const split = key.split(':::'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moduleName
and containingFile
retrieval can probably be combined, right now they both split.
Yeah. But it's also another bug because the previous method doesn't work for ts/js file creation, probably because we changed to not load new files unless it's already loaded.
Nope. this is added because |
Due to a change in svelte-check 3.5.2 (likely sveltejs/language-tools#2146), we can no longer have composite enabled, as svelte-check spits out errors about files in other project references not being listed in included files. This should hopefully not make a difference to us, as we weren't taking advantage of TypeScript's project compilation, as svelte-check doesn't support it, and we use esbuild for JS conversion.
Due to a change in svelte-check 3.5.2 (likely sveltejs/language-tools#2146), we can no longer have composite enabled, as svelte-check spits out errors about files in other project references not being listed in included files. This should hopefully not make a difference to us, as we weren't taking advantage of TypeScript's project compilation, as svelte-check doesn't support it, and we use esbuild for JS conversion.
#2132
This PR moved the tracking of "document is open by the client" to document so it can be copied over to ts snapshot and create a new
documentManager.openClientDocument
to replaceopenDoucment
in existing places. This will mark the file as client files in one method call, so we don't have to addmarkAsOpenByClient
to all existing tests. The reason that we need client files is that files might be opened by the client and not in the project files. One reason is that the user has an empty include in the tsconfig or has the default one. Also, we didn't watch Svelte files with File Watcher. So the new svelte file won't be in the project files. We probably should do it for something likegit checkout
, but that can be a separate PR.Alternatively, we could also create agetClientSnapshot
method to replace the currentLanguageServiceContainer.getSnaphsot
method ingetLSAndTSDoc
. This should mark any document that is passed in as a client file. But I haven't checked if this would cause thedep/index.ts
in #2132 to be marked as a client file.I have to use a TypeScript internal API and add a layer of synchronization because of a module resolution bug. The way
getSnapshot
prevents the problem before the amount of root files have changed so that TypeScript will check more thoroughly. The existing test is different from how it'll work in typical cases. It probably worked when it was introduced, but we later changed to not rungetSnapshot
in new ts/js files, so it's not actually preventing the error.