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

[wip] improvement: autocomplete functions #2883

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Light2Dark
Copy link
Contributor

@Light2Dark Light2Dark commented Nov 17, 2024

📝 Summary

Fixes #2877

  • increase docstring limit so complete docstring hints would show up more often
  • remove regex as it doesn't recognize certain inputs. (I'm worried about responsiveness but it's okay locally)
  • allow hints to appear in a bracket def abc(# <---- when the cursor is here

🔍 Description of Changes

There are still some odd / inconsistent behaviours, so this fix isn't foolproof.

📋 Checklist

  • I have read the contributor guidelines.
  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • I have added tests for the changes made.
  • I have run the code and verified that it works as expected.

📜 Reviewers

@akshayka OR @mscolnick

Copy link

vercel bot commented Nov 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marimo-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 19, 2024 0:34am
marimo-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 19, 2024 0:34am

@Light2Dark Light2Dark changed the title [wip] improvement: autocomplete functions improvement: autocomplete functions Nov 17, 2024
@Light2Dark Light2Dark changed the title improvement: autocomplete functions [wip] improvement: autocomplete functions Nov 17, 2024
@Light2Dark
Copy link
Contributor Author

Light2Dark commented Nov 17, 2024

I see there is an issue with some code_completion requests not resolving. It ends up that the autocomplete feels flaky.

frontend/src/core/codemirror/completion/Autocompleter.ts

export const AUTOCOMPLETER = new DeferredRequestRegistry<
  Omit<CodeCompletionRequest, "id">,
  CompletionResultMessage | null
>(
  "autocomplete-result",
  async (requestId, req) => {
    await sendCodeCompletionRequest({
      id: requestId,
      ...req,
    });
  },
  // We don't care about previous requests
  // so we just resolve them with an empty response.
  // { resolveExistingRequests: () => null }, // for example, commenting this out improves it. Existing reqs are handled
);

Playing around with this code, I can see the autocomplete not working 100% of the time. Still looking into why.

fig = px.bar(x=["a", "b", "c"], y=[1, 3, 2])
fig.upda

Copy link
Contributor

@akshayka akshayka left a comment

Choose a reason for hiding this comment

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

Thanks for exploring this — our completion could definitely use improvements. Left a comment.

@@ -60,7 +60,6 @@ export const Autocompleter = {
info: () => constructCompletionInfoNode(option.completion_info),
};
}),
validFor: /^\w*$/,
Copy link
Contributor

Choose a reason for hiding this comment

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

I am concerned about the performance hit from this.

Instead of deleting, can we fix this regex? From looking at the video in your issue, I wonder if /^\w+$/ would be better.

Copy link
Contributor Author

@Light2Dark Light2Dark Nov 19, 2024

Choose a reason for hiding this comment

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

thanks @akshayka , you are right about the performance hit.
I've been a little stuck because any regex doesn't work well with other libraries, eg polars df

df = pl.DataFrame({
    "a": [1,2]
})
df.clo# <---- cursor here doesn't autocomplete

I don't know why I'm so stuck unfortunately 🥲, anyways i modified this regex for a minor improvement.

Comment on lines -50 to -52
if (tooltip) {
return null;
}
Copy link
Contributor Author

@Light2Dark Light2Dark Nov 19, 2024

Choose a reason for hiding this comment

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

another thing @akshayka , this removal introduces some side effects. It's not ideal.

df = pl.DataFrame({
  "a": [1,2],# <--- cursor here will pop up an autocomplete for Dataframe which overrides Enter key
})

I am keen to revert this, an ideal solution is to display as just a tooltip, it would take me too long to implement imo :/. (unless you have some pointers, getting pretty lost haha)

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

Successfully merging this pull request may close these issues.

Autocomplete not always working
2 participants