Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Literals and operators in Component Browser #12420

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

farmaazon
Copy link
Contributor

Pull Request Description

Fixes #12372

Screencast.From.2025-03-05.15-34-18.mp4

Important Notes

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • Unit tests have been written where possible.
  • [ ] If meaningful changes were made to logic or tests affecting Enso Cloud integration in the libraries,
    or the Snowflake database integration, a run of the Extra Tests has been scheduled.
    • If applicable, it is suggested to paste a link to a successful run of the Extra Tests.

input.switchToCodeEditMode()
return Ok()
}
if (component.suggestionId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestionId is a number, and AFAIK the protocol allows it to be 0.

fixBoundaries() {
const open = this.open
const close = this.close
if (open != null && close == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the literal is multiline, close must remain null. It is multiline if open.length > 1.

This function could use some unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I guess setBoundaries also needs this logic?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setBoundaries is a very low-level operation that may break the validity of the AST in various ways, we might remove it or comment it as only for use in tests.

let literal: Ast.MutableTextLiteral | Ast.NumericLiteral | undefined =
Ast.TextLiteral.tryParse(text.value)
if (literal == null) {
literal = Ast.NumericLiteral.tryParse(text.value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a tryParseWithSign allowing negative numbers. This logic could use unit test coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unit tests were once completely removed for input.ts, because CB got huge redesign and we didn't know if it will be stable. For now, I just (re) added tests for cases fixed by this PR.

watch(toRef(props, 'filtering'), () => (displayedSelectedComponentIndex.value = 0))
const filtering = computed(() => {
const currentModule = projectStore.moduleProjectPath
return new Filtering(props.filter, currentModule?.ok ? currentModule.value : undefined)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a little simpler with unwrapOr.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentModule may be undefined, so I wouldn't avoid ?:

return sourceNodeIdentifier.value ? `${sourceNodeIdentifier.value}.${text}` : text
return (
sourceNodeIdentifier.value ?
/^[a-zA-Z]/.test(text) ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically an identifier can start with a character other than ASCII letters; we could handle that by exposing to WASM an entry point to the lexer so that we can see if the first token is a (lexical) identifier.

I suppose this is ok for an initial implementation but let's add a TODO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, implementation in rust should be quite easy; I just assumed this is too simple case for it.

But here you pointed me that it's not that simple case.

Copy link

github-actions bot commented Mar 5, 2025

🧪 Storybook is successfully deployed!

📊 Dashboard:

@farmaazon farmaazon changed the title Literals and operators in Comonent Browser Literals and operators in Component Browser Mar 6, 2025
@farmaazon farmaazon requested a review from kazcw March 6, 2025 13:01
${'"text"'} | ${'"text"'}
${"'text'"} | ${"'text'"}
${"'text"} | ${"'text'"}
${"'''text"} | ${"'''text"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Negative numeric literal case?

${'read'} | ${'operator2'} | ${'operator2.read'}
${'read "file"'} | ${'operator2'} | ${'operator2.read "file"'}
${'+ 2'} | ${'operator1'} | ${'operator1 + 2'}
${'+ 3'} | ${'operator2'} | ${'operator2 + 3'}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more good cases:

  • Operators without space
  • - without space--to make sure we don't treat that as a negative literal here

@@ -284,8 +285,7 @@ export function useComponentBrowserInput(
function applySourceNode(text: string) {
return (
sourceNodeIdentifier.value ?
/^[a-zA-Z]/.test(text) ?
`${sourceNodeIdentifier.value}.${text}`
startsWithIdentifier(sourceNodeIdentifier.value) ? `${sourceNodeIdentifier.value}.${text}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
startsWithIdentifier(sourceNodeIdentifier.value) ? `${sourceNodeIdentifier.value}.${text}`
startsWithIdentifier(text) ? `${sourceNodeIdentifier.value}.${text}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CB Improvements - literals and operators
2 participants