diff options
author | 2023-08-30 02:49:08 +0200 | |
---|---|---|
committer | 2023-08-30 02:49:08 +0200 | |
commit | f5bd26a7a231737eb3c67432ea72e3b5940a2405 (patch) | |
tree | e37f5176731b0fc2384fde1084b61ede11c1b975 /subprojects/frontend/src/xtext/ContentAssistService.ts | |
parent | feat(frontend): hide isolated nodes (diff) | |
download | refinery-f5bd26a7a231737eb3c67432ea72e3b5940a2405.tar.gz refinery-f5bd26a7a231737eb3c67432ea72e3b5940a2405.tar.zst refinery-f5bd26a7a231737eb3c67432ea72e3b5940a2405.zip |
fix(frontend): completion cache invalidation
In some cases, especially with an empty editor, trying to map completions over
the last changes may result in a RangeError. If unhandled, the error corrupts
editor state.
Diffstat (limited to 'subprojects/frontend/src/xtext/ContentAssistService.ts')
-rw-r--r-- | subprojects/frontend/src/xtext/ContentAssistService.ts | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/subprojects/frontend/src/xtext/ContentAssistService.ts b/subprojects/frontend/src/xtext/ContentAssistService.ts index fd30c4f9..ac8ab36a 100644 --- a/subprojects/frontend/src/xtext/ContentAssistService.ts +++ b/subprojects/frontend/src/xtext/ContentAssistService.ts | |||
@@ -248,10 +248,20 @@ export default class ContentAssistService { | |||
248 | if (lastTo === undefined) { | 248 | if (lastTo === undefined) { |
249 | return true; | 249 | return true; |
250 | } | 250 | } |
251 | const [transformedFrom, transformedTo] = this.mapRangeInclusive( | 251 | let transformedFrom: number; |
252 | lastFrom, | 252 | let transformedTo: number; |
253 | lastTo, | 253 | try { |
254 | ); | 254 | [transformedFrom, transformedTo] = this.mapRangeInclusive( |
255 | lastFrom, | ||
256 | lastTo, | ||
257 | ); | ||
258 | } catch (error) { | ||
259 | if (error instanceof RangeError) { | ||
260 | log.debug('Invalidating cache due to invalid range', error); | ||
261 | return true; | ||
262 | } | ||
263 | throw error; | ||
264 | } | ||
255 | let invalidate = false; | 265 | let invalidate = false; |
256 | transaction.changes.iterChangedRanges((fromA, toA) => { | 266 | transaction.changes.iterChangedRanges((fromA, toA) => { |
257 | if (fromA < transformedFrom || toA > transformedTo) { | 267 | if (fromA < transformedFrom || toA > transformedTo) { |