File tree Expand file tree Collapse file tree 1 file changed +25
-5
lines changed Expand file tree Collapse file tree 1 file changed +25
-5
lines changed Original file line number Diff line number Diff line change 11import View from './view'
2- import { parse } from '@influxdata/flux-lsp-browser'
2+ import { parse , format_from_js_file } from '@influxdata/flux-lsp-browser'
33import { parseQuery } from 'src/shared/contexts/query'
44import { isFlagEnabled } from 'src/shared/utils/featureFlag'
55
@@ -24,14 +24,34 @@ export default register => {
2424 const ast = isFlagEnabled ( 'fastFlows' )
2525 ? parseQuery ( query )
2626 : parse ( query )
27- if ( ! ast . body . length ) {
27+ const expressions = ast . body . filter (
28+ p => p . type === 'ExpressionStatement'
29+ )
30+
31+ if ( ! expressions . length ) {
2832 return ''
2933 }
30- } catch {
34+
35+ expressions . forEach ( e => {
36+ let _ast
37+ if ( e . expression ?. call ?. callee ?. name !== 'yield' ) {
38+ _ast = parse ( `${ e . location . source } |> limit(n: 100)` )
39+ e . expression = _ast . body [ 0 ] . expression
40+ e . location = _ast . body [ 0 ] . location
41+ return
42+ }
43+
44+ _ast = parse (
45+ `${ e . expression . argument . location . source } |> limit(n: 100) |> ${ e . expression . call . location . source } `
46+ )
47+ e . expression = _ast . body [ 0 ] . expression
48+ e . location = _ast . body [ 0 ] . location
49+ } )
50+ return format_from_js_file ( ast )
51+ } catch ( e ) {
52+ console . error ( e )
3153 return ''
3254 }
33-
34- return `${ query } |> limit(n: 100)`
3555 } ,
3656 } )
3757}
You can’t perform that action at this time.
0 commit comments