-
Notifications
You must be signed in to change notification settings - Fork 188
Add new completion API #866
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
Changes from all commits
2a13eb5
0812061
7cff503
5dd6977
0a15bf6
3ea2e42
0b58895
12e196e
8320d05
a9e7672
c43c278
e21b1a9
a86c249
2f5aeae
59c6c0b
534ae8a
c3d8807
40ef4be
ea29e0b
7d78abb
97ae903
ea4dd30
8a11721
f9d8bb9
793ec40
10ad58a
d2505b0
542b489
d5a5d62
d7fd65d
f46548a
ff9e0ae
2f504f7
896dcef
87ab9e3
1744b16
5782b46
316d29d
64627ee
8dd14b3
f47083e
542245e
44a3b2a
33496ac
7b154e6
c0805be
b528475
2497a45
9fe640a
a99cff7
49ccda6
cc475e9
61099bc
9e54c83
6fed5d3
dae5eba
1ccb7ab
036e432
d974c22
e3f580c
f207bf2
4468f8a
f38aaa0
bc687e5
07f7824
51bbd4d
b5c0de6
34ae9e1
18c47e3
6e596e4
9d0d7ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import sublime | ||
| from .typing import List | ||
|
|
||
|
|
||
| class RestoreLines: | ||
| def __init__(self): | ||
| self.saved_lines = [] # type: List[dict] | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: The code before it did this:
The code in this commit does this.
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. If I done the same thing as John did in his gist: For me it looks easier to adjust the view state to the state it was when the request is send, Either way, I really want to hear the feedback from you all |
||
|
|
||
| def save_lines(self, locations: List[int], view: sublime.View) -> None: | ||
| change_id = view.change_id() | ||
|
|
||
| for point in locations: | ||
| line = view.line(point) | ||
| change_region = (line.begin(), line.end()) | ||
| text = view.substr(line) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anything which prevents the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regions can't be serialized for transmission in However, you should be able to use
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guess the python 3.3 version of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't know you could do that
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'Region' object is not iterable. Looks like the LSP plugin is still using python 3.3. |
||
|
|
||
| self.saved_lines.append({ | ||
| "change_id": change_id, | ||
| "change_region": change_region, | ||
| "text": text, | ||
| # cursor will be use retore the cursor the te exact position | ||
| "cursor": point | ||
| }) | ||
|
|
||
| def to_dict(self): | ||
| return { | ||
| "saved_lines": self.saved_lines | ||
| } | ||
|
|
||
| @staticmethod | ||
| def from_dict(dictionary): | ||
| restore_lines = RestoreLines() | ||
| restore_lines.saved_lines = dictionary["saved_lines"] | ||
| return restore_lines | ||
|
|
||
| def restore_lines(self, edit: sublime.Edit, view: sublime.View) -> None: | ||
| # restore lines contents | ||
| # insert back lines from the bottom to top | ||
| for saved_line in reversed(self.saved_lines): | ||
| change_id = saved_line['change_id'] | ||
| begin, end = saved_line['change_region'] | ||
| change_region = sublime.Region(begin, end) | ||
|
|
||
| transform_region = view.transform_region_from(change_region, change_id) | ||
| view.erase(edit, transform_region) | ||
| view.insert(edit, transform_region.begin(), saved_line['text']) | ||
|
|
||
| # restore old cursor position | ||
| view.sel().clear() | ||
| for saved_line in self.saved_lines: | ||
| view.sel().add(saved_line["cursor"]) | ||
Uh oh!
There was an error while loading. Please reload this page.