Skip to content

Commit 1a259c1

Browse files
authored
feat(5622): reinit full composition block at once (#5630)
* feat(5622): enable reinit of full composition block * fix: local testing showed that forceMoveMarkers is not an accurate heuristic. Use a proper determination for if change is from the Lsp.
1 parent aae2204 commit 1a259c1

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/languageSupport/languages/flux/lsp/connection.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ class LspConnectionManager {
155155
}
156156

157157
_editorChangeIsFromLsp(change) {
158-
// heuristic. Not 100% accurate.
159-
return !!change.forceMoveMarkers
158+
return change.text?.includes('|> yield(name: "_editor_composition")')
160159
}
161160

162161
_editorChangeIsWithinComposition(change) {
@@ -311,13 +310,34 @@ class LspConnectionManager {
311310
* buffer of executeCommands, send to Lsp at a throttled pace (hack timeouts)
312311
* longterm: middleware? changes in Lsp?
313312
*/
314-
if (toAdd.bucket || toAdd.measurement) {
315-
const payload = {bucket: toAdd.bucket?.name || this._session.bucket?.name}
316-
if (toAdd.measurement) {
317-
payload['measurement'] = toAdd.measurement
313+
const numFieldChanges =
314+
(toAdd.fields?.length || 0) + (toRemove.fields?.length || 0)
315+
const numTagValueChanges =
316+
(toAdd.tagValues?.length || 0) + (toRemove.tagValues?.length || 0)
317+
const reInitBlock =
318+
toAdd.bucket ||
319+
toAdd.measurement ||
320+
numFieldChanges + numTagValueChanges > 1
321+
322+
if (reInitBlock) {
323+
const payload = {
324+
bucket: toAdd.bucket?.name || this._session.bucket?.name,
325+
}
326+
if (toAdd.measurement || this._session.measurement) {
327+
payload['measurement'] = toAdd.measurement || this._session.measurement
328+
}
329+
if (toAdd.fields || this._session.fields) {
330+
payload['fields'] = toAdd.fields || this._session.fields
331+
}
332+
if (toAdd.tagValues || this._session.tagValues) {
333+
payload['tagValues'] = (
334+
toAdd.tagValues || this._session.tagValues
335+
).map(({key, value}) => [key, value])
318336
}
319337
this._insertBuffer([ExecuteCommand.CompositionInit, payload])
338+
return // re-initialize full block. no more requests needed.
320339
}
340+
321341
if (toRemove.fields?.length) {
322342
toRemove.fields.forEach(value =>
323343
this._insertBuffer([ExecuteCommand.CompositionRemoveField, {value}])

src/languageSupport/languages/flux/lsp/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export type ExecuteCommandInjectField = ExecuteCommandInjectMeasurement
7474
export interface CompositionInitParams {
7575
bucket: string
7676
measurement?: string
77+
fields?: string[]
78+
tagValues?: string[]
7779
}
7880

7981
interface CompositionValueParams extends ExecuteCommandParams {

0 commit comments

Comments
 (0)