Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit bcc816a

Browse files
authored
feat(svelte): Support 'got to defintion' for multiple definitions and 'find implementations' (#64349)
This commit adds the necessary logic to open the explorer tab for multiple references and for implementations. I basically copied what @camdencheek did for the references tab. ## Test plan Hover over `adapt` in http://localhost:5173/github.com/sveltejs/kit@65931f276ac2102032e3032c864a472eee19b7bb/-/blob/packages/kit/src/exports/vite/index.js?L890 and click 'got to definition'. The explore panel with should open with the definitions tab selected. I wasn't able to test the find implementations logic because I don't know for which language we have this implemented.
1 parent 24ab529 commit bcc816a

File tree

4 files changed

+29
-22
lines changed

4 files changed

+29
-22
lines changed

client/web-sveltekit/src/lib/CodeMirrorBlob.svelte

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
getScrollSnapshot as getScrollSnapshot_internal,
168168
} from './codemirror/utils'
169169
import { registerHotkey } from './Hotkey'
170-
import { goToDefinition, openImplementations } from './repo/blob'
170+
import { goToDefinition } from './repo/blob'
171171
import { createLocalWritable } from './stores'
172172
173173
export let blobInfo: BlobInfo
@@ -230,16 +230,23 @@
230230
filePath: blobInfo.filePath,
231231
languages: blobInfo.languages,
232232
}
233-
const { openReferences } = getExplorePanelContext()
233+
const { openReferences, openDefinitions, openImplementations } = getExplorePanelContext()
234234
$: codeIntelExtension = codeIntelAPI
235235
? createCodeIntelExtension({
236236
api: {
237237
api: codeIntelAPI,
238238
documentInfo: documentInfo,
239-
goToDefinition: (view, definition, options) =>
240-
goToDefinition(documentInfo, view, definition, options),
239+
goToDefinition: (view, definition, options) => {
240+
if (definition.type === 'multiple') {
241+
// Open the explore panel with the definitions
242+
openDefinitions({ documentInfo, occurrence: definition.occurrence })
243+
} else {
244+
goToDefinition(documentInfo, view, definition, options)
245+
}
246+
},
241247
openReferences: (_view, documentInfo, occurrence) => openReferences({ documentInfo, occurrence }),
242-
openImplementations,
248+
openImplementations: (_view, documentInfo, occurrence) =>
249+
openImplementations({ documentInfo, occurrence }),
243250
createTooltipView: options => new HovercardView(options.view, options.token, options.hovercardData),
244251
},
245252
// TODO(fkling): Support tooltip pinning

client/web-sveltekit/src/lib/codenav/ExplorePanel.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
1313
export interface ExplorePanelContext {
1414
openReferences(occurrence: ActiveOccurrence): void
15+
openDefinitions(occurrence: ActiveOccurrence): void
16+
openImplementations(occurrence: ActiveOccurrence): void
1517
}
1618
1719
const exploreContextKey = Symbol('explore context key')

client/web-sveltekit/src/lib/repo/blob.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ import {
2626
*/
2727
const MINIMUM_GO_TO_DEF_LATENCY_MILLIS = 20
2828

29+
/**
30+
* This will either:
31+
* - Show a tooltip indicating that no definition was found or that the user is already at the definition.
32+
* - Go to the definition if it is a single definition.
33+
* - Show a tooltip indicating that multiple definitions were found (but do nothing else).
34+
*/
2935
export async function goToDefinition(
3036
documentInfo: DocumentInfo,
3137
view: EditorView,
@@ -82,7 +88,7 @@ export async function goToDefinition(
8288
case 'multiple': {
8389
void goto(locationToURL(documentInfo, definition.destination, 'def'))
8490
if (offset) {
85-
showTemporaryTooltip(view, 'Not supported yet: Multiple definitions', offset, 2000)
91+
showTemporaryTooltip(view, 'Multiple definitions found', offset, 2000)
8692
}
8793
break
8894
}
@@ -100,14 +106,3 @@ export function openReferences(view: EditorView, documentInfo: DocumentInfo, occ
100106
})
101107
svelteGoto(url)
102108
}
103-
104-
export function openImplementations(
105-
view: EditorView,
106-
_documentInfo: DocumentInfo,
107-
occurrence: Definition['occurrence']
108-
): void {
109-
const offset = positionToOffset(view.state.doc, occurrence.range.start)
110-
if (offset) {
111-
showTemporaryTooltip(view, 'Not supported yet: Find implementations', offset, 2000)
112-
}
113-
}

client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/(code)/+layout.svelte

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,15 @@
112112
disableScope: true,
113113
})
114114
const exploreInputs = writable<ExplorePanelInputs>({})
115+
function openExploreTab(usageKindFilter: SymbolUsageKind, occurrence: ActiveOccurrence) {
116+
exploreInputs.set({ activeOccurrence: occurrence, usageKindFilter })
117+
// Open the tab when we find references
118+
selectedTab = TabPanels.References
119+
}
115120
setExplorePanelContext({
116-
openReferences(occurrence: ActiveOccurrence) {
117-
exploreInputs.set({ activeOccurrence: occurrence, usageKindFilter: SymbolUsageKind.REFERENCE })
118-
// Open the tab when we find references
119-
selectedTab = TabPanels.References
120-
},
121+
openReferences: openExploreTab.bind(null, SymbolUsageKind.REFERENCE),
122+
openDefinitions: openExploreTab.bind(null, SymbolUsageKind.DEFINITION),
123+
openImplementations: openExploreTab.bind(null, SymbolUsageKind.IMPLEMENTATION),
121124
})
122125
$: usagesConnection = $exploreInputs.activeOccurrence
123126
? getUsagesStore(

0 commit comments

Comments
 (0)