-
Notifications
You must be signed in to change notification settings - Fork 49
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
Rewrite of the abbreviation feature. #240
Rewrite of the abbreviation feature. #240
Conversation
430a49f
to
c564341
Compare
@@ -116,7 +116,7 @@ module.exports = { | |||
"no-throw-literal": "error", | |||
"no-trailing-spaces": "error", | |||
"no-undef-init": "error", | |||
"no-underscore-dangle": "error", | |||
"no-underscore-dangle": "off", |
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.
This setting is turned off to allow fields that can be mutated privately (private _foo: string
) but that are readonly publically (get foo(): string { return this._foo; }
).
package.json
Outdated
"key": "enter", | ||
"mac": "enter", | ||
"when": "editorTextFocus && editorLangId == lean && lean.input.isActive && !suggestWidgetVisible && !renameInputVisible && !inSnippetMode && !quickFixWidgetVisible && (!vim.active || vim.mode == 'Insert')" | ||
"when": "editorTextFocus && !suggestWidgetVisible && editorLangId == lean && lean.input.isActive" |
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.
Can you update the README to remove lean.input.convertWithNewline
as well?
Maybe you could even add the GIF showing off the abbreviation from your PR comment.
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.
Can you update the README to remove lean.input.convertWithNewline as well?
This is currently not mentioned in the readme - so there is nothing to remove.
Maybe you could even add the GIF showing off the abbreviation from your PR comment.
I would wait until I experimented with the intellisense feature. Also, this GIF is not really meant to document the feature - too much is going on in it.
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.
Whoops, I thought I'd added all options to the README when I revamped it, but I guess I skipped this one. Sorry for the noise!
There is still a cursor positioning bug - it happens when typing |
67e5d37
to
f5fcac6
Compare
* Fixes some bugs in multi-cursor scenarios. * Gets rid of several hacks by introducing a more general system. * Removes now obsolete command "lean.input.convertWithNewline". * Abbreviations are now replaced as soon as possible if the abbreviation is unique. * Adds mobx dependency and makes the abbreviation config observable.
f5fcac6
to
ce67fb0
Compare
Fixed! |
Sorry, I haven't tested this myself, but it looks like this changes the behaviour without an option to revert to the original behaviour is that right? Personally I like the sound of the changes, but I'm a bit worried that we should at least allow people to use the old system if they already have the muscle memory to press tab/enter at the appropriate moment and dont want to change. |
I will add a setting for that which can disable this behavior! |
Thanks for putting effort into improving the input mode! Some comments: The new directory structure is very "enterprisey".
Also feel free to put more functions/classes in a single file, this is not java. Please run What is the reason to add a new Finally, please add the setting that Alex mentioned. |
Like the docs say: It is way easier to get correctness with offset based datastructures, as you would need to detect line breaks in text that got inserted. This is the reason for some bugs in the current implementation, if the multiple cursors are added to the same line.
Can do that, but I still find it confusing that it is called
I also can do that, but personally, I'm against it. The "abbreviation" feature consists of several subfeatures - the rewriting, the hover-provider and maybe someday an autocompletion. The rewrite feature has these four entities (
I used to put many things into single files as it has been done in
This is strange, I can try to fix that. I also highly recommend to setup prettier for formatting, enable strict mode and lift some eslint/tslint rules. Currently, tslint is doing stuff that other tools can do better.
Will do that. |
This makes sense!
Good point! Feel free to rename it to
The overriding principle here is consistency with the rest of the codebase, which doesn't use directory hierarchies either. And I'm not even against subdirectories. I like The
Feel free to add prettier if you'd like. (But in a different PR please.) |
It very much is (currently)! But I can only recommend separating feature code from core/infrastructure code. I'll remove the
I understand your point and I will change it, but there was some reasoning behind chosing those names. If you configure the indentation in VS Code of nested folders, long names are not problematic anymore.
I will!
There was also a technical change that required me to move it - I changed the code to bundle the json file directly as source, rather than loading it as file dynamically. However, if
I can try to fix that, even though I guess I need to fallback to the mechanism used in the current master. |
Ah, if there's a good reason then that's fine too. We have quite a few users though that contribute to the file but don't develop the extension, so it'd be great if it was still easy to find (from the github page).
I agree, and that's why I said that a new directory for the abbreviations feature is a great idea. Different projects have different organization styles. It is better to be consistent within a project than to conform (partially) to a style guide, no matter how well-thought out it may be. The optimal organization also depends on the size of a project, a 10-line script requiring a different setup than a 100k line project. I am sure that at your company all new repositories conform to these style guides, and this is great for consistency and uniformity, and makes it easier for new people to get started on a project. But this is not your company, and following such an elaborate style guide can even be detrimental since nobody here is familiar with it, negating some of the advantages. This holds doubly if the style is only followed partially, for a single feature. |
Very true and I will change these things in this PR to be more consistent with the existing code. Nonetheless, I think with 25 files in the |
|
🎉 |
// Wait for VS Code to trigger `onDidChangeTextEditorSelection` | ||
await waitForNextTick(); |
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.
My understanding is that this timeout is non-deterministic, and is the cause of the "sometimes the replacement doesn't happen" bug. It happens more when lean is busy.
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.
"sometimes the replacement doesn't happen"
This happens if the user changes the text buffer after the replacement is issued but before it is committed. This is unavoidable, it can only be made less likely to happen (I only learned recently about this, sorry for not having taken this into account when I wrote that code).
Internally, VS Code has a version number per text document that is incremented on every edit. Edits are sent asynchronously to the extensions and if an extension issues an (async) text modification it is only applied if the version of the target document has not changed in the meantime.
waitForNextTick
makes it more likely that a user can change the text buffer before the extension can commit the text modification.
However, waitForNextTick
is also required to position the cursor correctly after the replacment has been committed.
Your fix is a good workaround, but maybe the extension can actually try a second time to perform this replacement. Sadly (afaik) VS Code does not allow transactional updates that involve text and cursor modification.
See #239.
Smart replacing if abbreviation is unique:
Multi-cursor demo:
Except (4) and the bug fixes, no semantics should be changed with this PR.