Add ability to create named constant without code (#5840)

* Add support for forcing kcl input create variable

* Command palette padding tweak

* Make traverse function work for ExpressionStatements

* Add utilities for getting earliest safe index in AST

* Fix the insertIndex logic to not be based on the selection anymore

* Add workflow to create a named constant

* Fix bug with nameEndInDigits matcher

* Tweak command config

* Add a three-dot menu to feature tree pane to create parameters

* Add E2E test for create parameter flow

* Remove edit flow oops

* Fix tsc error

* Fix E2E test

* Update named constant position in edit flow test

* Add tags into consideration for safe insert index

Per @Irev-dev's helpful feedback, with unit tests!
This commit is contained in:
Frank Noirot
2025-03-19 11:58:53 -04:00
committed by GitHub
parent af492d2cb6
commit 533fa749b2
21 changed files with 477 additions and 26 deletions

View File

@ -0,0 +1,44 @@
import { assertParse, initPromise } from 'lang/wasm'
import { getIdentifiersInProgram } from './getIndentifiersInProgram'
function identifier(name: string, start: number, end: number) {
return {
type: 'Identifier',
name,
start,
end,
}
}
beforeAll(async () => {
await initPromise
})
describe(`getIdentifiersInProgram`, () => {
it(`finds no identifiers in an empty program`, () => {
const identifiers = getIdentifiersInProgram(assertParse(''))
expect(identifiers).toEqual([])
})
it(`finds a single identifier in an expression`, () => {
const identifiers = getIdentifiersInProgram(assertParse('55 + a'))
expect(identifiers).toEqual([identifier('a', 5, 6)])
})
it(`finds multiple identifiers in an expression`, () => {
const identifiers = getIdentifiersInProgram(assertParse('a + b + c'))
expect(identifiers).toEqual([
identifier('a', 0, 1),
identifier('b', 4, 5),
identifier('c', 8, 9),
])
})
it(`finds all the identifiers in a normal program`, () => {
const program = assertParse(`x = 5 + 2
y = x * 2
z = y + 1`)
const identifiers = getIdentifiersInProgram(program)
expect(identifiers).toEqual([
identifier('x', 14, 15),
identifier('y', 24, 25),
])
})
})