|
1 |
| -import * as monaco from 'monaco-editor'; |
| 1 | + |
| 2 | +import { Monaco } from '@monaco-editor/react' |
2 | 3 | import { EditorUIProps } from '../remix-ui-editor'
|
3 | 4 | import { monacoTypes } from '@remix-ui/editor';
|
4 | 5 | export class RemixHoverProvider implements monacoTypes.languages.HoverProvider {
|
5 | 6 |
|
6 | 7 | props: EditorUIProps
|
7 |
| - triggerRangeActions: { |
8 |
| - id: string |
9 |
| - range: monacoTypes.Range |
10 |
| - action: () => void |
11 |
| - }[] |
12 |
| - |
13 |
| - constructor(props: any) { |
| 8 | + monaco: Monaco |
| 9 | + constructor(props: any, monaco: any) { |
14 | 10 | this.props = props
|
15 |
| - this.triggerRangeActions = [] |
| 11 | + this.monaco = monaco |
16 | 12 | }
|
17 | 13 |
|
18 |
| - addTriggerRangeAction (id: string, range: monacoTypes.Range, action: () => void) { |
19 |
| - this.triggerRangeActions.push({ id, range, action }) |
20 |
| - } |
21 |
| - |
22 |
| - removeTriggerRangeAction (id: string) { |
23 |
| - this.triggerRangeActions = this.triggerRangeActions.filter(action => action.id !== id) |
24 |
| - } |
25 |
| - |
26 |
| - async provideHover (model: monacoTypes.editor.ITextModel, position: monacoTypes.Position): Promise<monacoTypes.languages.Hover> { |
27 |
| - for (const action of this.triggerRangeActions) { |
28 |
| - if (action.range.startLineNumber <= position.lineNumber && |
29 |
| - action.range.endLineNumber >= position.lineNumber && |
30 |
| - action.range.startColumn <= position.column && |
31 |
| - action.range.endColumn >= position.column) { |
32 |
| - action.action() |
33 |
| - } |
34 |
| - } |
35 |
| - |
| 14 | + provideHover = async function (model: monacoTypes.editor.ITextModel, position: monacoTypes.Position): Promise<monacoTypes.languages.Hover> { |
36 | 15 | const cursorPosition = this.props.editorAPI.getHoverPosition(position)
|
37 | 16 | const nodeAtPosition = await this.props.plugin.call('codeParser', 'definitionAtPosition', cursorPosition)
|
38 | 17 | const contents = []
|
@@ -212,7 +191,7 @@ export class RemixHoverProvider implements monacoTypes.languages.HoverProvider {
|
212 | 191 | },1000)
|
213 | 192 |
|
214 | 193 | return {
|
215 |
| - range: new monaco.Range( |
| 194 | + range: new this.monaco.Range( |
216 | 195 | position.lineNumber,
|
217 | 196 | position.column,
|
218 | 197 | position.lineNumber,
|
|
0 commit comments