-
Notifications
You must be signed in to change notification settings - Fork 185
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
Add new completion API #866
Add new completion API #866
Conversation
Co-Authored-By: Raoul Wols <r@primef.actor>
Dont replace them
…ed and that the completion item text will be inserted, But because edit_region.end() will take in account the previously typed text(the prefix), which is erased, we wont be using the end edit region. because it deletes some lines that it shouldn't, so we use the current_point as the end of the edit Region
TODO: |
@@ -7,15 +7,16 @@ def __init__(self): | |||
self.saved_lines = [] # type: List[dict] |
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.
Feel free to correct me, I don't know if I used the new API correctly :)
Here is my feedback:
I want to highlight the differences between the new api, and the code before it:
The code before it did this:
- It copied the
row
,text
,cursor
position of each line, right before sending the request. - On selecting a completion item, it inserted back the text on each row.
END RESULT: It brought the lines in a state like they were when the completions were requested.
The code in this commit does this.
- It copies the
change_id
,change_region
(the region passed to thetransform_region_from
),text
andcursor
position for each line, right before sending the request. - On selecting a completion item, the transform_region_from returns a
transform_region
.transform_region
is used for removing and inserting back the previous text for each line.
view.erase(edit, transform_region)
view.insert(edit, transform_region.begin(), saved_line['text'])
// I could probably use view.replace instead of erase and insert
END RESULT: It brings the lines in a state like they were when the completions were requested.
You may have noticed that I did this a bit differently, than what John did in his gist.
https://gist.github.com/jskinner/4dfa6d86f848e1e1e583883507369b67#file-async_edits-py-L238-L244
def fill_completions(self, edits):
# The server has sent us a series of edits it wants to be made when
# the completion command is run, however the user may have edited the
# buffer since the request want sent. Adjust the response from the
# server to account for these edits
for c in self.changes_since_sent:
edits = [(transform_region(r, c), text) for r, text in edits]
If I done the same thing as John did in his gist:
I would have to adjust the response from the server to account for all view edits that occurred,
and apply all TextChange-s to all completion items.
But that to me looks like a lot of work.
For me it looks easier to adjust the view state to the state it was when the request is send,
than to adjust the response from the server to account all the possible edits that may have had occurred.
Either way, I really want to hear the feedback from you all
And don't take me wrong with what I just said :)
@jskinner, just for confirmation, the |
row, _col = view.rowcol(point) | ||
line = view.line(point) | ||
change_region = (line.begin(), line.end()) | ||
text = view.substr(line) |
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.
Anything which prevents the line
to be stored directly? Doing so would avoid converting region->tuple->region
.
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.
Regions can't be serialized for transmission in run_command
, which is required for the commit completion command.
However, you should be able to use tuple(region)
now that regions are iterable. I also think this step should happen at the communication edge were it is necessary to do so and not for the internal storage to make this kind of relation more obvious. I'm still not seing where the use case I assumed actually occurs.
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.
Guess the python 3.3 version of sublime.Region
does not support iteration. This will be available as soon as we can move to python 3.8
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 didn't know you could do that tuple(region)
with a Region. Cool :)
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.
'Region' object is not iterable.
saved_line['change_region'] = tuple(saved_line['change_region'])
TypeError: 'Region' object is not iterable
Looks like the LSP plugin is still using python 3.3.
Some problems: When I supplement the completion by typing more characters, the completion widget goes away. I don't get a completion widget at all sometimes. In the gif below I expect to at least see a completion for the "time" variable: I'm guessing this is due to incomplete completions. I'm not sure what the dynamic is here. |
@FichteFoll auto_complete_triggers is tested against the character just inserted, and auto_complete_selector is tested at the position before the inserted character (a change from ST3), but after it has been inserted |
Sorry, I didn't mean to say the latest changes specifically, just that I've noticed it with the latest changes included. :) I've compared to master branch (7fb166d). |
See the bug, too, using the LSP-json completions. With regards to @jskinner's statements the triggers and selectors of the view are set to:
The It looks like ST only uses the first character of the trigger, thus retriggering AC after committing a value which ends with Not sure whether the trigger is intended to be of one character only by design or whether it is a bug. |
@rwols #866 (comment) I want to say that this PR is getting quiet large :) @rwols @rchl If you guys are happy with the changes till now, |
Does tests/test_completion.py not crash for you? It segfaults SublimeText for me. |
I'm okay with merging to st4000-exploration branch provided that the tests pass. Outstanding issues:
|
No, they run fine:
|
Strange, ST4 segfaults here when running |
OK, when I run all tests with |
I won't claim that I've reviewed it but at least with my testing, I could not find more issues (than the one still remaining) |
Thanks for the response. |
@rwols I created issues for some of the things you wrote, but skipped these ones because I don't have enough information on what exactly needs to be done:
@deathaxe if you don't have nothing against, |
NEW:
completion kind symbols in autocomplete (symbols will probably be a subject of change)
![Screenshot from 2020-01-30 19-53-15](https://user-images.githubusercontent.com/22029477/73480467-39aec100-439a-11ea-9478-77dd6938b78b.png)
support deprecated flag in completion items(don't know any server that implements this, but here is an image of a deprecated completion item)
I haven't been able to run any completion unit test, just to tell you.
There are some things in this PR, that I wish I had done better, but I was not able to(due to my limited knowledge, I will put some comments to mark those things)