Skip to content

Conversation

@WhyPenguins
Copy link
Contributor

@WhyPenguins WhyPenguins commented May 7, 2025

Description

This PR adds a code hinting window that automatically pops up when typing. It shows the parameters for the current function, and other overloads can be switched between with the arrows on the side. It can be triggered to show up using Ctrl-Space, and hidden using Escape.

Peek 2025-05-07 10-45

The bulk of the logic is in codeHinter.js. It handles the following:

  • parsing text in the CodeMirror editor to figure out the context around the user's cursor
    • only the information about which function the cursor is in is used currently, but it calculates further scope in case we ever want nested code hinting.
  • Finding matching functions from the SplashKit API
  • Actually displaying the hint window, positioning it within the code editor window, and handling switching between overloads.

It also includes some other minor changes:

  • Styling fix to make the text cursor visible
  • Styling fix to limit which disabled buttons have the wait cursor
  • Adjustments to how and when auto-complete shows up

Known issues:

  • Since it doesn't do any type deduction, the overload initially displayed doesn't always match what the user is actually doing. For instance many of SplashKit functions can take either a string ID, or a bitmap/sound/font, etc - it'll just default to the string one. It does try to guess based on the number of arguments though, and I think is generally 'good enough'? 😅 In the future perhaps we can keep track of variables and start doing some type deduction as well 😃
  • Similar to the auto-complete, the API currently loaded in is the JavaScript one, meaning C++ doesn't show proper types in the function signatures. I considered this a more general problem that should probably be solved by having a per-language API file, could be in the languageDefinitions? But yeah figured it was out of scope for this.
  • The auto-complete and this have completely different styles 😅. The auto-complete looks kind of flat IMO, perhaps it could be updated to look more like the hint window? But can also go the other way as well.

Thanks if you can take a look at this! I'd definitely appreciate any feedback on how the code could be improved, any aspects that seem like they could cause issues longer term, or if there are any remaining UI issues with it that I overlooked haha.

I'm also wondering if perhaps it could get in the way at times - maybe there should be a way to permanently toggle it on/off? It'd also be cool to consider how it could be further expanded - I know VS Code can show function/parameter descriptions as well, perhaps that could be future work from this. So hoping to make sure the code is reasonably readable haha.

Thanks! 😃

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Tried out the code hinting on a variety of different functions to see how the window behaved and whether the overloads worked well enough.
  • Tried it at different locations and screen sizes as well to make sure it fit within the code editor.
  • Tried to break it by rapidly clicking around and adjusting things, fixed any bugs that popped up.

Testing Checklist

  • Tested in latest Chrome
  • Tested in latest Safari
  • Tested in latest Firefox

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have requested a review from ... on the Pull Request

     when already fully typed out, for consistency.
Previous when typing COLOR_RED the suggestion for COLOR_RED would show, but
once COLOR_RED was fully typed out the suggestion box would vanish.
This was intended, but I think was the wrong choice - it's better to
still allow the user to hit enter and not suddenly end up on a newline.
 - Shows when typing
 - Ctrl-Space can trigger manually, Escape hides it
 - Some other small related UI adjustments
@github-actions
Copy link

github-actions bot commented May 7, 2025

🐋 PR Preview!
Preview at https://thoth-tech.github.io/SplashkitOnline/pr-previews/119
for commit a73ce4d

Copy link
Collaborator

@Oliver-Quail Oliver-Quail left a comment

Choose a reason for hiding this comment

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

Overall a very good new feature.
Please see comments for some suggested changes regarding best practice

flexDirection: "column"
}});

let functionHint = elem("div", {class: "sk-contents sk-notification sk-function-hint sk-contents-focusable", tabindex: "10"}, [
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just out of interest why is tabindex set to 10?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly this is just to get the sk-contents-focusable focus-within outline working 😅, any tabindex will do. Better suggestions welcome there!

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.

2 participants