diff options
Diffstat (limited to 'subprojects/frontend/src/xtext/OccurrencesService.ts')
-rw-r--r-- | subprojects/frontend/src/xtext/OccurrencesService.ts | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/subprojects/frontend/src/xtext/OccurrencesService.ts b/subprojects/frontend/src/xtext/OccurrencesService.ts index bc865537..21fe8644 100644 --- a/subprojects/frontend/src/xtext/OccurrencesService.ts +++ b/subprojects/frontend/src/xtext/OccurrencesService.ts | |||
@@ -1,15 +1,16 @@ | |||
1 | import { Transaction } from '@codemirror/state'; | 1 | import { Transaction } from '@codemirror/state'; |
2 | 2 | ||
3 | import type { EditorStore } from '../editor/EditorStore'; | 3 | import type EditorStore from '../editor/EditorStore'; |
4 | import type { IOccurrence } from '../editor/findOccurrences'; | 4 | import type { IOccurrence } from '../editor/findOccurrences'; |
5 | import type { UpdateService } from './UpdateService'; | 5 | import Timer from '../utils/Timer'; |
6 | import { getLogger } from '../utils/logger'; | 6 | import getLogger from '../utils/getLogger'; |
7 | import { Timer } from '../utils/Timer'; | 7 | |
8 | import { XtextWebSocketClient } from './XtextWebSocketClient'; | 8 | import type UpdateService from './UpdateService'; |
9 | import type XtextWebSocketClient from './XtextWebSocketClient'; | ||
9 | import { | 10 | import { |
10 | isConflictResult, | 11 | isConflictResult, |
11 | occurrencesResult, | 12 | OccurrencesResult, |
12 | TextRegion, | 13 | type TextRegion, |
13 | } from './xtextServiceResults'; | 14 | } from './xtextServiceResults'; |
14 | 15 | ||
15 | const FIND_OCCURRENCES_TIMEOUT_MS = 1000; | 16 | const FIND_OCCURRENCES_TIMEOUT_MS = 1000; |
@@ -33,7 +34,7 @@ function transformOccurrences(regions: TextRegion[]): IOccurrence[] { | |||
33 | return occurrences; | 34 | return occurrences; |
34 | } | 35 | } |
35 | 36 | ||
36 | export class OccurrencesService { | 37 | export default class OccurrencesService { |
37 | private readonly store: EditorStore; | 38 | private readonly store: EditorStore; |
38 | 39 | ||
39 | private readonly webSocketClient: XtextWebSocketClient; | 40 | private readonly webSocketClient: XtextWebSocketClient; |
@@ -94,7 +95,7 @@ export class OccurrencesService { | |||
94 | this.findOccurrencesTimer.schedule(); | 95 | this.findOccurrencesTimer.schedule(); |
95 | return; | 96 | return; |
96 | } | 97 | } |
97 | const parsedOccurrencesResult = occurrencesResult.safeParse(result); | 98 | const parsedOccurrencesResult = OccurrencesResult.safeParse(result); |
98 | if (!parsedOccurrencesResult.success) { | 99 | if (!parsedOccurrencesResult.success) { |
99 | log.error( | 100 | log.error( |
100 | 'Unexpected occurences result', | 101 | 'Unexpected occurences result', |
@@ -107,14 +108,25 @@ export class OccurrencesService { | |||
107 | } | 108 | } |
108 | const { stateId, writeRegions, readRegions } = parsedOccurrencesResult.data; | 109 | const { stateId, writeRegions, readRegions } = parsedOccurrencesResult.data; |
109 | if (stateId !== this.updateService.xtextStateId) { | 110 | if (stateId !== this.updateService.xtextStateId) { |
110 | log.error('Unexpected state id, expected:', this.updateService.xtextStateId, 'got:', stateId); | 111 | log.error( |
112 | 'Unexpected state id, expected:', | ||
113 | this.updateService.xtextStateId, | ||
114 | 'got:', | ||
115 | stateId, | ||
116 | ); | ||
111 | this.clearOccurrences(); | 117 | this.clearOccurrences(); |
112 | return; | 118 | return; |
113 | } | 119 | } |
114 | const write = transformOccurrences(writeRegions); | 120 | const write = transformOccurrences(writeRegions); |
115 | const read = transformOccurrences(readRegions); | 121 | const read = transformOccurrences(readRegions); |
116 | this.hasOccurrences = write.length > 0 || read.length > 0; | 122 | this.hasOccurrences = write.length > 0 || read.length > 0; |
117 | log.debug('Found', write.length, 'write and', read.length, 'read occurrences'); | 123 | log.debug( |
124 | 'Found', | ||
125 | write.length, | ||
126 | 'write and', | ||
127 | read.length, | ||
128 | 'read occurrences', | ||
129 | ); | ||
118 | this.store.updateOccurrences(write, read); | 130 | this.store.updateOccurrences(write, read); |
119 | } | 131 | } |
120 | 132 | ||