-
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: patch file reference and navigate to items in ts plugin (#2174)
- Loading branch information
1 parent
1d53bdc
commit 62a1c94
Showing
3 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
packages/typescript-plugin/src/language-service/file-references.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,32 @@ | ||
import type ts from 'typescript/lib/tsserverlibrary'; | ||
import { isNotNullOrUndefined, isSvelteFilePath } from '../utils'; | ||
import { SvelteSnapshotManager } from '../svelte-snapshots'; | ||
|
||
export function decorateFileReferences( | ||
ls: ts.LanguageService, | ||
snapshotManager: SvelteSnapshotManager | ||
): void { | ||
const getFileReferences = ls.getFileReferences; | ||
ls.getFileReferences = (fileName: string) => { | ||
const references = getFileReferences(fileName); | ||
|
||
return references | ||
.map((ref) => { | ||
if (!isSvelteFilePath(ref.fileName)) { | ||
return ref; | ||
} | ||
|
||
let textSpan = snapshotManager.get(ref.fileName)?.getOriginalTextSpan(ref.textSpan); | ||
|
||
if (!textSpan) { | ||
return; | ||
} | ||
|
||
return { | ||
...ref, | ||
textSpan | ||
}; | ||
}) | ||
.filter(isNotNullOrUndefined); | ||
}; | ||
} |
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
55 changes: 55 additions & 0 deletions
55
packages/typescript-plugin/src/language-service/navigate-to-items.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,55 @@ | ||
import type ts from 'typescript/lib/tsserverlibrary'; | ||
import { isGeneratedSvelteComponentName, isNotNullOrUndefined, isSvelteFilePath } from '../utils'; | ||
import { SvelteSnapshotManager } from '../svelte-snapshots'; | ||
|
||
export function decorateNavigateToItems( | ||
ls: ts.LanguageService, | ||
snapshotManager: SvelteSnapshotManager | ||
): void { | ||
const getNavigateToItems = ls.getNavigateToItems; | ||
ls.getNavigateToItems = ( | ||
searchValue: string, | ||
maxResultCount?: number, | ||
fileName?: string, | ||
excludeDtsFiles?: boolean | ||
) => { | ||
const navigationToItems = getNavigateToItems( | ||
searchValue, | ||
maxResultCount, | ||
fileName, | ||
excludeDtsFiles | ||
); | ||
|
||
return navigationToItems | ||
.map((item) => { | ||
if (!isSvelteFilePath(item.fileName)) { | ||
return item; | ||
} | ||
|
||
if ( | ||
item.name.startsWith('__sveltets_') || | ||
(item.name === 'render' && !item.containerName) | ||
) { | ||
return; | ||
} | ||
|
||
let textSpan = snapshotManager | ||
.get(item.fileName) | ||
?.getOriginalTextSpan(item.textSpan); | ||
|
||
if (!textSpan) { | ||
if (isGeneratedSvelteComponentName(item.name)) { | ||
textSpan = { start: 0, length: 1 }; | ||
} else { | ||
return; | ||
} | ||
} | ||
|
||
return { | ||
...item, | ||
textSpan | ||
}; | ||
}) | ||
.filter(isNotNullOrUndefined); | ||
}; | ||
} |