-
-
Notifications
You must be signed in to change notification settings - Fork 10
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: Autocomplete using parameter objects #410
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty good! The indentation changes don't work so well, but the autocomplete is greatly appreciated 🙂
let tabs = "" | ||
for (let i = 0; i < indents; i++) { tabs += "\t" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let tabs = "" | |
for (let i = 0; i < indents; i++) { tabs += "\t" } | |
const tabs = "\t".repeat(indents) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, neat!
app/javascript/src/stores/editor.js
Outdated
"word-wrap": false | ||
"word-wrap": false, | ||
"autocomplete-parameter-objects": false, | ||
"autocomplete-min-parameter-size": 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR description says 3, but this is set to 2. Which one should it be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, it should be 2. I had it at 3 initially, but 2 felt better
if (transaction.transactions.every(tr => ["input.paste", "input.complete"].includes(tr.annotation(Transaction.userEvent)))) { | ||
const [range] = transaction.changedRanges | ||
const text = transaction.state.doc.toString().slice(range.fromB, range.toB) | ||
const indents = getIndentForLine(view.state, range.fromB) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is not all sunshine and rainbows, sadly
brave_IJ8rPnV7Up.mp4
I think this could benefit from reapplying indentation on each line of the pasted content?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made some improvements and it should be much better. It's not quite perfect but the imperfections make enough sense. VSCode has similar (but different) inconsistencies. I think this is about as close as we can get without fully parsing the text, which would be too slow for larger texts anyway.
const useParameterObject = $settings["autocomplete-parameter-objects"] && params.args_length >= $settings["autocomplete-min-parameter-size"] | ||
const apply = v.args.map(a => { | ||
let string = a.default?.toString().toLowerCase().replaceAll(",", "") | ||
if (useParameterObject) string = `\n\t${ a.name }: ${ string }` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to have a limit on when each parameter is put on a new line and when not?
If I was one of those people that put autocomplete-min-parameter-size
to 1, maybe I'd like for autocomplete to not expand the parameter object into multiple lines if the parameter amount is <3 or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Martín Rodríguez <[email protected]>
refactor: Move indent function to separate file
Since commit Mitcheljager#410 there is an error when copypasting a single line (no problem with more than 1 line): "Uncaught RangeError: Invalid count value: -2" Adding Math.max() as a temporary solution, not sure what is causing it? Adding back a bugfix (prevent auto-indents on enter from adding up infinitely when the cursor is outside of an open bracket) that disappeared with the change to some of the functions added a selectionDirection constant to prevent the selection from flipping around when tabbing (cursor used to always jump to 'to' position, even when it started at 'from')
bugfix for indents after #410
This PR adds an options to the settings dropdown to autocomplete using parameter objects. All autocompletes will use parameter objects instead of their regular format. When you change the settings the completions map is regenerated with the new corresponding format.
Along with that settings there's a setting to only do this if the completion has more than x arguments, defaulting to 2. If it has less than the given amount the regular format will be used. This is mostly to prevent silly parameter objects like
Button({ Button: Melee })
.Since the autocompletions can be multi line I added a function that transforms transactions in CodeMirror that contain new lines to use the expected amount of tabs. An added benefit of this is that this fixes a bug with pasting code that contains tabs that would only be indented correctly on the first line