-
Notifications
You must be signed in to change notification settings - Fork 40
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 no-missing-import getting confused on incremental file changes #338
Merged
+80
−34
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,16 @@ function emitDirectModuleImportWithName(moduleSpecifier: string, node: Node, con | |
if (cache != null) { | ||
result = context.ts.resolveModuleNameFromCache(moduleSpecifier, node.getSourceFile().fileName, cache, mode); | ||
} | ||
if (result == null) { | ||
// Result could not be found from the cache, try and resolve module without using the | ||
// cache. | ||
result = context.ts.resolveModuleName( | ||
moduleSpecifier, | ||
node.getSourceFile().fileName, | ||
context.program.getCompilerOptions(), | ||
context.ts.createCompilerHost(context.program.getCompilerOptions()) | ||
); | ||
} | ||
Comment on lines
+171
to
+180
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixes the issue. The rest of the PR is refactor & tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Genius. Nice find. |
||
} | ||
|
||
if (result?.resolvedModule?.resolvedFileName != null) { | ||
|
17 changes: 0 additions & 17 deletions
17
packages/lit-analyzer/src/lib/analyze/store/analyzer-dependency-store.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,3 @@ | ||
export interface AnalyzerDependencyStore { | ||
hasTagNameBeenImported(fileName: string, tagName: string): boolean; | ||
} | ||
|
||
//importedComponentDefinitionsInFile = new Map<string, ComponentDefinition[]>(); | ||
|
||
/** | ||
* Returns if a component for a specific file has been imported. | ||
* @param fileName | ||
* @param tagName | ||
*/ | ||
/*hasTagNameBeenImported(fileName: string, tagName: string): boolean { | ||
for (const file of this.importedComponentDefinitionsInFile.get(fileName) || []) { | ||
if (file.tagName === tagName) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/vscode-lit-plugin/src/test/fixtures/missing-import.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import "./my-defined-element.js"; | ||
|
||
// Pretending this is the Lit html function | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
declare const html: any; | ||
|
||
html`<my-defined-element></my-defined-element><my-other-element></my-other-element>`; |
9 changes: 9 additions & 0 deletions
9
packages/vscode-lit-plugin/src/test/fixtures/my-defined-element.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export class MyDefinedElement extends HTMLElement {} | ||
|
||
customElements.define("my-defined-element", MyDefinedElement); | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"my-defined-element": MyDefinedElement; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/vscode-lit-plugin/src/test/fixtures/my-other-element.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export class MyOtherElement extends HTMLElement {} | ||
|
||
customElements.define("my-other-element", MyOtherElement); | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"my-other-element": MyOtherElement; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What's the difference between these methods?
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.
There is no difference except it looked like the intent was that
importedComponentDefinitionsInFile
should beprivate
, withabsorbComponentDefinitionsForFile
being the public method to do this logic.You can see the
dependencyStore
class defined here: https://github.com/runem/lit-analyzer/pull/338/files#diff-faaba94b3ffda920023b5e0ff3b54f7137199117142a418b7bd79df7e8951c5eR6-R9This is a pure refactor, no logic change. I can revert this line if it keeps it simpler.