Skip to content

Commit

Permalink
feat(frontend): go to definition in toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
kris7t committed Dec 15, 2024
1 parent e386ced commit 18c0b37
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
10 changes: 10 additions & 0 deletions subprojects/frontend/src/editor/EditorButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import RedoIcon from '@mui/icons-material/Redo';
import SaveIcon from '@mui/icons-material/Save';
import SaveAsIcon from '@mui/icons-material/SaveAs';
import SearchIcon from '@mui/icons-material/Search';
import ShortcutIcon from '@mui/icons-material/ShortcutOutlined';
import UndoIcon from '@mui/icons-material/Undo';
import WarningIcon from '@mui/icons-material/Warning';
import IconButton from '@mui/material/IconButton';
Expand Down Expand Up @@ -150,6 +151,15 @@ export default observer(function EditorButtons({
</ToggleButton>
</MuiTooltip>
</ToggleButtonGroup>
<Tooltip title="Go to definition">
<IconButton
disabled={!editorStore?.opened}
onClick={() => editorStore?.goToDefinition()}
color="inherit"
>
<ShortcutIcon fontSize="small" />
</IconButton>
</Tooltip>
<Tooltip title="Automatic format">
<IconButton
disabled={!editorStore?.opened}
Expand Down
3 changes: 2 additions & 1 deletion subprojects/frontend/src/editor/EditorStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,9 @@ export default class EditorStore {
return this.client.hoverTooltip(pos);
}

goToDefinition(pos: number): void {
goToDefinition(pos?: number): boolean {
this.client?.goToDefinition(pos);
return true;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions subprojects/frontend/src/editor/createEditorState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ export default function createEditorState(
...completionKeymap,
...foldKeymap,
...historyKeymap,
{
key: 'F3',
run: () => store.goToDefinition(),
},
// Enable accepting completions with tab, overrides `Tab` from
// `indentWithTab` if there is an active completion.
{ key: 'Tab', run: acceptCompletion },
Expand Down
2 changes: 1 addition & 1 deletion subprojects/frontend/src/xtext/OccurrencesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export default class OccurrencesService {
this.store.updateOccurrences(write, read, goToFirst, pos);
}

goToDefinition(pos: number): Promise<void> {
goToDefinition(pos?: number): Promise<void> {
return this.updateOccurrences(pos, true);
}
}
2 changes: 1 addition & 1 deletion subprojects/frontend/src/xtext/XtextClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export default class XtextClient {
return this.hoverService.hoverTooltip(pos);
}

goToDefinition(pos: number): void {
goToDefinition(pos?: number): void {
this.occurrencesService.goToDefinition(pos).catch((e) => {
log.error('Error while fetching occurrences', e);
});
Expand Down

0 comments on commit 18c0b37

Please sign in to comment.