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

feat: Trigger autocomplete even outside bindings #39446

Merged
merged 12 commits into from
Mar 7, 2025

Conversation

hetunandu
Copy link
Member

@hetunandu hetunandu commented Feb 26, 2025

Description

Shows autocomplete with results in binding brackets {{ <result> }} when the user is typing something outside the binding

Fixes #39112

Automation

/ok-to-test tags="@tag.All"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/13699728311
Commit: cd3816b
Cypress dashboard.
Tags: @tag.All
Spec:


Thu, 06 Mar 2025 14:46:52 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features
    • Introduced a new utility function for determining when to show autocomplete suggestions in the code editor.
    • Enhanced the code editor autocomplete for more context-aware suggestions and improved cursor handling, resulting in a smoother editing experience.
  • Refactor
    • Standardized input formatting across components to ensure consistent handling of data in widget interactions.

Copy link
Contributor

coderabbitai bot commented Feb 26, 2025

Walkthrough

The changes update several Cypress test cases and code editor utilities. In the tests, the serialized JSON and array values passed to methods now have an appended space character. In the code editor components, type safety improvements are applied and a new utility function (shouldShowAutocompleteWithBindingBrackets) is added. Additionally, autocomplete and completion logic in both the hint helpers and the TernService have been modified to better handle cursor context and input formatting.

Changes

File(s) Summary
app/.../Debugger/Widget_property_navigation_spec.ts, app/.../Widgets/JSONForm/JSONForm_CurrencyField_spec.ts, app/.../Widgets/TableV2/AddNewRow1_spec.js Modified test input strings by appending a space character to serialized JSON/array values in method calls (EnterJSContext and UpdatePropertyFieldValue).
app/.../CodeEditor/codeEditorUtils.ts, app/.../CodeEditor/hintHelpers.ts, app/.../autocomplete/CodemirrorTernService.ts Enhanced type safety in editor utilities, added shouldShowAutocompleteWithBindingBrackets, and adjusted autocomplete logic including completion formatting and cursor handling.
app/.../CodeEditor/hintHelpers.test.ts, app/.../autocomplete/__tests__/TernServer.test.ts Updated test cases to change expected behavior from closing hints to showing hints, and modified mock return strategies for editor values and cursor positions.
app/.../CodeMirrorEditorMock.ts Added a new method getModeAt to the MockCodemirrorEditor for enhanced testing capabilities.

Sequence Diagram(s)

sequenceDiagram
    participant Editor as Code Editor
    participant Hint as Hint Helper
    participant Util as Autocomplete Utils
    participant Tern as Tern Service

    Editor->>Hint: User types in editor
    Hint->>Util: Check if autocomplete should be triggered
    Util-->>Hint: Return decision (show/hide)
    Hint->>Tern: Request code completions based on context
    Tern-->>Editor: Return formatted completion suggestions
Loading

Possibly related PRs

Suggested labels

Query & JS Pod, Javascript Product

Suggested reviewers

  • ApekshaBhosale
  • sagar-qa007
  • ankitakinger

Poem

In code, a space finds its part,
A tiny tweak, a subtle art.
Autocomplete stirs with a brand new tone,
Hints and completions now finely honed.
Tests align, and logic sings—
A small change that elegantly rings!


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 42870f2 and cd3816b.

📒 Files selected for processing (3)
  • app/client/src/components/editorComponents/CodeEditor/hintHelpers.test.ts (3 hunks)
  • app/client/src/utils/autocomplete/__tests__/TernServer.test.ts (2 hunks)
  • app/client/test/__mocks__/CodeMirrorEditorMock.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-build / client-build
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-prettier / prettier-check
🔇 Additional comments (6)
app/client/test/__mocks__/CodeMirrorEditorMock.ts (1)

22-22: Good addition of getModeAt method.

Adding this mock method enhances the CodeMirror mock object's capabilities for testing, particularly for scenarios involving mode detection at specific positions.

app/client/src/components/editorComponents/CodeEditor/hintHelpers.test.ts (3)

69-69: Changed behavior from closing to showing hints.

The test case now expects autocomplete to show hints when typing non-binding text like "ABC". This change supports the PR's objective to trigger autocomplete even outside bindings.


95-95: Changed behavior from closing to showing hints for partial object/function pattern.

Similar to the previous case, the test now expects autocomplete to show hints when typing "{test(", aligning with the feature's goal of providing more consistent autocomplete behavior.


105-105: Switched from mockReturnValueOnce to mockReturnValue.

Using mockReturnValue instead of mockReturnValueOnce ensures the mock consistently returns the same value for multiple calls during testing, which provides more reliable test behavior for autocomplete functionality.

app/client/src/utils/autocomplete/__tests__/TernServer.test.ts (2)

217-217: Consistent cursor position across multiple calls.

Changed from mockReturnValueOnce to mockReturnValue to ensure the cursor position remains consistent for all calls during test execution.


693-695: Added mock value for getValue method.

This provides a specific test string for testing autocomplete behavior with a realistic code snippet, which enhances the test case with a concrete example of incomplete code that should trigger autocomplete.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@hetunandu hetunandu added the ok-to-test Required label for CI label Feb 26, 2025
@github-actions github-actions bot added Enhancement New feature or request IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product labels Feb 26, 2025
@hetunandu
Copy link
Member Author

/build-deploy-preview

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/13540563905.
Workflow: On demand build Docker image and deploy preview.
skip-tests: . env: .
PR: 39446.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-39446.dp.appsmith.com

@hetunandu
Copy link
Member Author

/build-deploy-preview

Copy link

github-actions bot commented Mar 4, 2025

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/13651914111.
Workflow: On demand build Docker image and deploy preview.
skip-tests: . env: .
PR: 39446.
recreate: .

@hetunandu
Copy link
Member Author

/build-deploy-preview

Copy link

github-actions bot commented Mar 4, 2025

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/13652662670.
Workflow: On demand build Docker image and deploy preview.
skip-tests: . env: .
PR: 39446.
recreate: .

Copy link

github-actions bot commented Mar 4, 2025

Deploy-Preview-URL: https://ce-39446.dp.appsmith.com

@hetunandu
Copy link
Member Author

/build-deploy-preview

Copy link

github-actions bot commented Mar 5, 2025

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/13670017466.
Workflow: On demand build Docker image and deploy preview.
skip-tests: . env: .
PR: 39446.
recreate: .

Copy link

github-actions bot commented Mar 5, 2025

Deploy-Preview-URL: https://ce-39446.dp.appsmith.com

@hetunandu hetunandu marked this pull request as ready for review March 6, 2025 07:18
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
app/client/cypress/e2e/Regression/ClientSide/Widgets/JSONForm/JSONForm_CurrencyField_spec.ts (1)

51-51: 🛠️ Refactor suggestion

Remove Sleep usage.

Using agHelper.Sleep(500) violates the coding guidelines. Replace with proper Cypress waiting strategies.

- agHelper.Sleep(500);
+ agHelper.WaitUntil(() => agHelper.IsElementVisible(locators._jsonFormInputField("employee_id")), 
+                    "Wait for input field to be ready");
🧹 Nitpick comments (1)
app/client/src/utils/autocomplete/CodemirrorTernService.ts (1)

1378-1389: Fixed mode detection condition for JavaScript.

Changed the condition from checking if mode name is not JavaScript to checking if it is JavaScript. This ensures expected type is only set when appropriate.

Consider adding a comment explaining why the condition was changed to make the intent clearer.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e9f7f9c and 42870f2.

📒 Files selected for processing (6)
  • app/client/cypress/e2e/Regression/ClientSide/Debugger/Widget_property_navigation_spec.ts (1 hunks)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/JSONForm/JSONForm_CurrencyField_spec.ts (1 hunks)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/AddNewRow1_spec.js (1 hunks)
  • app/client/src/components/editorComponents/CodeEditor/codeEditorUtils.ts (2 hunks)
  • app/client/src/components/editorComponents/CodeEditor/hintHelpers.ts (2 hunks)
  • app/client/src/utils/autocomplete/CodemirrorTernService.ts (7 hunks)
✅ Files skipped from review due to trivial changes (1)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/AddNewRow1_spec.js
🧰 Additional context used
📓 Path-based instructions (1)
`app/client/cypress/**/**.*`: Review the following e2e test ...

app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
  • app/client/cypress/e2e/Regression/ClientSide/Debugger/Widget_property_navigation_spec.ts
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/JSONForm/JSONForm_CurrencyField_spec.ts
🧠 Learnings (1)
app/client/src/utils/autocomplete/CodemirrorTernService.ts (1)
Learnt from: ashit-rath
PR: appsmithorg/appsmith#33726
File: app/client/src/utils/autocomplete/CodemirrorTernService.ts:199-199
Timestamp: 2024-11-12T08:11:36.416Z
Learning: The `entityDef` property in `CodeMirrorTernService` class within `CodemirrorTernService.ts` is intentionally initialized as an empty object.
🪛 Biome (1.9.4)
app/client/src/components/editorComponents/CodeEditor/codeEditorUtils.ts

[error] 10-10: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-build / client-build
🔇 Additional comments (13)
app/client/cypress/e2e/Regression/ClientSide/Widgets/JSONForm/JSONForm_CurrencyField_spec.ts (1)

26-26: Be consistent with JSON serialization.

The addition of an empty space after JSON.stringify() appears to be a deliberate change, likely to trigger proper parsing behavior in the JSONForm component.

app/client/cypress/e2e/Regression/ClientSide/Debugger/Widget_property_navigation_spec.ts (1)

86-86: Be consistent with JSON serialization.

The addition of an empty space after JSON.stringify() appears to be a deliberate change, likely to trigger proper parsing behavior in the JSONForm component, consistent with changes in other test files.

app/client/src/components/editorComponents/CodeEditor/hintHelpers.ts (3)

10-10: New import for autocomplete with binding brackets.

This import adds the utility function needed to determine if autocomplete should be shown outside binding brackets.


49-49: Changed default behavior to show autocomplete.

Initial value of shouldShow is now true rather than false, which aligns with the PR objective to make autocomplete more available.


55-57: Added support for showing autocomplete outside binding brackets.

This condition checks if autocomplete should be shown with binding brackets even when the cursor is not inside a binding, enhancing the autocomplete experience. The new functionality correctly preserves the existing behavior for other scenarios.

app/client/src/components/editorComponents/CodeEditor/codeEditorUtils.ts (3)

9-9: Improved type safety for removeNewLineChars.

Type parameter changed from any to string for better type safety.


13-13: Enhanced type handling in getInputValue.

Improves type safety by:

  1. Changing parameter type from any to unknown
  2. Explicitly ensuring the return type is always a string

This change avoids potential type-related issues and makes the function more robust.

Also applies to: 20-20


170-191: New function to determine if autocomplete should be shown outside binding brackets.

This function implements the core logic for the new feature, enabling autocomplete suggestions for single-word inputs outside binding brackets, while maintaining existing behavior for SQL mode and special inputs.

The logic correctly excludes:

  • SQL mode (where different autocomplete rules apply)
  • Empty values or slash commands (which have different handling)
  • Multi-word inputs (where autocomplete would be less relevant)
app/client/src/utils/autocomplete/CodemirrorTernService.ts (5)

24-24: Added import for cursor binding detection.

Imports the utility function needed to check if cursor is inside binding brackets.


520-521: Added detection for JavaScript actions.

New variable to determine if the current field is a JavaScript action, which influences autocomplete presentation.


556-556: Added cursor position binding detection.

Determines if the cursor is inside binding brackets to control the autocomplete behavior appropriately.


596-599: Enhanced autocomplete presentation for non-binding contexts.

When cursor is outside binding brackets and not in a JS action field, this wraps completions with {{ }} to maintain the expected binding format while providing autocomplete anywhere in the editor.

This is the key implementation for the PR's objective of triggering autocomplete outside binding brackets.


756-773: Improved cursor positioning after completion selection.

Added logic to detect if completion ends with binding brackets and position the cursor appropriately:

  • For functions: Places cursor between parentheses
  • For completions with binding brackets: Places cursor before the closing brackets

This enhances user experience by placing the cursor in the most useful position after selecting an autocompletion.

ankitakinger
ankitakinger previously approved these changes Mar 6, 2025
@hetunandu hetunandu merged commit a3794dc into release Mar 7, 2025
85 checks passed
@hetunandu hetunandu deleted the feat/autocomplete-triggers branch March 7, 2025 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product ok-to-test Required label for CI User Testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: New triggers for autocomplete
2 participants