Skip to content

Commit d9f5780

Browse files
trying to fix Autocompletion tooltip stuttering
1 parent c2cc24e commit d9f5780

File tree

7 files changed

+155
-31
lines changed

7 files changed

+155
-31
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
This plugin uses **[Flow](https://github.com/facebook/flow)** (javascript static type checker from Facebook) under the hood.
66

7-
This is in **Beta** version for testing.
7+
This is in **BETA** version for **testing**.
88

99
It offers better **javascript autocomplete** and also a lot of features about creating, developing and managing **javascript projects**, such as:
1010

@@ -18,7 +18,7 @@ It offers better **javascript autocomplete** and also a lot of features about cr
1818
- JavaScript real-time errors
1919
- etc.
2020

21-
You could use it also in **existing projects** (see the [Wiki](https://github.com/pichillilorenzo/JavaScriptEnhancements/wiki))!
21+
You could use it also in **existing projects** (see the [Wiki](https://github.com/pichillilorenzo/JavaScriptEnhancements/wiki/Using-it-with-an-existing-project))!
2222

2323
It turns Sublime Text into a **JavaScript IDE** like!
2424

@@ -69,7 +69,7 @@ Manually:
6969

7070
If the plugin gives to you message errors like `Error during installation: "node.js" seems not installed on your system...` but instead you have installed node.js and npm (for example using [nvm](https://github.com/creationix/nvm)), then you could try to set your custom path in the [Global settings](https://github.com/pichillilorenzo/JavaScriptEnhancements/wiki/Global-settings) of the plugin and then restart Sublime Text.
7171

72-
If this not works too, then you could try to add the custom path that contains binaries of node.js and npm in the **`PATH`** key-value on the same JavaScript Enhancements settings file. This variable will be **concatenated** to the **$PATH** environment variable, so you could use the same syntax in it. After that you need to restart Sublime Text. Example of a global setting for `Linux` that uses `nvm`:
72+
If this not works too, then you could try to add the custom path that contains binaries of node.js and npm in the **`PATH`** key-value on the same JavaScript Enhancements settings file. This variable will be **appended** to the **$PATH** environment variable, so you could use the same syntax in it. After that you need to restart Sublime Text. Example of a global setting for `Linux` that uses `nvm`:
7373

7474
```
7575
{
@@ -108,6 +108,10 @@ See the [Wiki](https://github.com/pichillilorenzo/JavaScriptEnhancements/wiki) f
108108

109109
Email me for any questions or doubts about this project on: [pichillilorenzo@gmail.com](mailto:pichillilorenzo@gmail.com)
110110

111+
### Issues
112+
113+
For any problems, open an issue with the Sublime Text console logs please!
114+
111115
### Feature request/enhancement
112116

113117
For feature requests or them enhancement, please open an issue with the corresponding label.

_generated_2018_01_02_at_20_54_26.py renamed to _generated_2018_01_03_at_03_39_39.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,9 +1230,10 @@ def init(self):
12301230
if result[0]:
12311231
sublime.active_window().status_message("JavaScript Enhancements - npm dependencies installed correctly.")
12321232
else:
1233+
print(result)
12331234
if os.path.exists(node_modules_path):
12341235
shutil.rmtree(node_modules_path)
1235-
sublime.error_message("Error during installation: can not install the npm dependencies for JavaScript Enhancements.")
1236+
sublime.error_message("Error during installation: can't install npm dependencies for JavaScript Enhancements plugin.\n\nThe error COULD be caused by the npm permission access (EACCES error), so in this case you need to repair/install node.js and npm in way that doesn't require \"sudo\" command.\n\nFor example you could use a Node Version Manager, such as \"nvm\" or \"nodenv\".\n\nTry to run \"npm install\" inside the package of this plugin to see what you get.")
12361237
# else:
12371238
# result = npm.update_all()
12381239
# if not result[0]:
@@ -2976,6 +2977,10 @@ def get(self, key):
29762977
import sublime, sublime_plugin
29772978
import os, tempfile
29782979

2980+
# list of threads that are used to check if there are
2981+
# multiple async completions tooltip queued (fix for tooltip stuttering)
2982+
javascript_completions_thread_list = []
2983+
29792984
def build_type_from_func_details(comp_details):
29802985
if comp_details :
29812986

@@ -3029,7 +3034,7 @@ def run_auto_complete(self):
30293034

30303035
def on_query_completions(self, view, prefix, locations):
30313036
# Return the pending completions and clear them
3032-
3037+
#
30333038
if not view.match_selector(
30343039
locations[0],
30353040
'source.js - string - comment'
@@ -3050,16 +3055,20 @@ def on_query_completions(self, view, prefix, locations):
30503055
self.completions_ready = False
30513056
return self.completions
30523057

3053-
sublime.set_timeout_async(
3054-
lambda: self.on_query_completions_async(
3055-
view, prefix, locations
3056-
)
3057-
)
3058+
global javascript_completions_thread_list
3059+
3060+
javascript_completions_thread_list.append(Util.create_and_start_thread(target=lambda: self.on_query_completions_async(view, prefix, locations, len(javascript_completions_thread_list)+1), thread_name="JavaScriptEnhancementsCompletions"))
3061+
3062+
# sublime.set_timeout_async(
3063+
# lambda: self.on_query_completions_async(
3064+
# view, prefix, locations
3065+
# )
3066+
# )
30583067

30593068
if not self.completions_ready or not self.completions:
30603069
return ([], sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
30613070

3062-
def on_query_completions_async(self, view, prefix, locations):
3071+
def on_query_completions_async(self, view, prefix, locations, index_thread):
30633072
self.completions = None
30643073

30653074
if not view.match_selector(
@@ -3152,8 +3161,16 @@ def on_query_completions_async(self, view, prefix, locations):
31523161
view = sublime.active_window().active_view()
31533162
sel = view.sel()[0]
31543163
if view.substr(view.word(sel)).strip() :
3164+
3165+
global javascript_completions_thread_list
3166+
3167+
if len(javascript_completions_thread_list) == 0 or index_thread+1 < len(javascript_completions_thread_list):
3168+
return
3169+
31553170
self.run_auto_complete()
31563171

3172+
javascript_completions_thread_list = []
3173+
31573174
def on_text_command(self, view, command_name, args):
31583175
sel = view.sel()[0]
31593176
if not view.match_selector(
@@ -3190,11 +3207,14 @@ def on_selection_modified_async(self, view) :
31903207
locations = list()
31913208
locations.append(selections[0].begin())
31923209

3193-
sublime.set_timeout_async(
3194-
lambda: self.on_query_completions_async(
3195-
view, "", locations
3196-
)
3197-
)
3210+
global javascript_completions_thread_list
3211+
3212+
javascript_completions_thread_list.append(Util.create_and_start_thread(target=lambda: self.on_query_completions_async(view, "", locations, len(javascript_completions_thread_list)+1), thread_name="JavaScriptEnhancementsCompletions"))
3213+
# sublime.set_timeout_async(
3214+
# lambda: self.on_query_completions_async(
3215+
# view, "", locations
3216+
# )
3217+
# )
31983218

31993219

32003220
import sublime, sublime_plugin

changelog/0.1.11.txt

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
v0.1.11
2+
3+
## Fixes
4+
5+
- Trying to fix "Autocompletion tooltip stutters" #5
6+
7+
8+
=================================================================
9+
** THIS PLUGIN IS IN BETA! Thanks for your support in advance! **
10+
=================================================================
11+
12+
If you like it, remember to star it ⭐ on GitHub: https://github.com/pichillilorenzo/JavaScriptEnhancements
13+
14+
** USAGE **
15+
===========
16+
17+
See how it works on the Wiki: 👉👉 https://github.com/pichillilorenzo/JavaScriptEnhancements/wiki 👈👈
18+
19+
20+
** WHAT IS THIS? **
21+
===================
22+
23+
This plugin uses Flow (javascript static type checker from Facebook) under the hood.
24+
25+
It offers better javascript autocomplete and a lot of features about creating,
26+
developing and managing javascript projects, such as:
27+
28+
- Cordova projects (run cordova emulate, build, compile, serve, etc. directly from Sublime Text!)
29+
- Ionic v1 and v2 projects (same as Cordova projects!)
30+
- Angular v1 and v2 projects
31+
- React projects
32+
- Express projects
33+
- Yeoman generators
34+
- Local bookmarks project
35+
- JavaScript real-time errors
36+
- etc.
37+
38+
You could use it also in existing projects (see the Wiki - https://github.com/pichillilorenzo/JavaScriptEnhancements/wiki/Using-it-with-an-existing-project)!
39+
40+
It turns Sublime Text into a JavaScript IDE like!
41+
42+
This project is based on my other Sublime Text plugin JavaScript Completions (https://github.com/pichillilorenzo/JavaScript-Completions)
43+
44+
** NOTE **
45+
If you want use this plugin, you may want uninstall/disable the JavaScript Completions plugin, if installed.
46+
47+
** OS SUPPORTED NOW **
48+
======================
49+
50+
👉 Linux (64-bit)
51+
👉 Mac OS X
52+
53+
❗❗ Dependencies ❗❗
54+
=======================
55+
56+
In order to work properly, this plugin has some dependencies:
57+
58+
👉 Sublime Text 3 (build 3124 or newer)
59+
👉 Node.js and npm (https://nodejs.org or nvm (https://github.com/creationix/nvm))
60+
👉 TerminalView sublime text plugin (https://github.com/Wramberg/TerminalView)
61+
62+
Not required, but useful for typescript files (Flow wont work on this type of files):
63+
64+
👉 TypeScript sublime text plugin (https://github.com/Microsoft/TypeScript-Sublime-Plugin)
65+
66+
** Flow Requirements **
67+
=======================
68+
69+
It use [Flow](https://github.com/facebook/flow) for type checking and auto-completions.
70+
71+
👉 Mac OS X
72+
👉 Linux (64-bit)
73+
👉 Windows (64-bit)
74+
75+
Email me for any questions or doubts about this new project on: pichillilorenzo@gmail.com
76+
77+
Thanks for your support! 😄😄
78+
79+
MIT License

helper/javascript_completions/on_query_completions_event_listener.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import sublime, sublime_plugin
22
import os, tempfile
33

4+
# list of threads that are used to check if there are
5+
# multiple async completions tooltip queued (fix for tooltip stuttering)
6+
javascript_completions_thread_list = []
7+
48
def build_type_from_func_details(comp_details):
59
if comp_details :
610

@@ -54,7 +58,7 @@ def run_auto_complete(self):
5458

5559
def on_query_completions(self, view, prefix, locations):
5660
# Return the pending completions and clear them
57-
61+
#
5862
if not view.match_selector(
5963
locations[0],
6064
'source.js - string - comment'
@@ -75,16 +79,20 @@ def on_query_completions(self, view, prefix, locations):
7579
self.completions_ready = False
7680
return self.completions
7781

78-
sublime.set_timeout_async(
79-
lambda: self.on_query_completions_async(
80-
view, prefix, locations
81-
)
82-
)
82+
global javascript_completions_thread_list
83+
84+
javascript_completions_thread_list.append(Util.create_and_start_thread(target=lambda: self.on_query_completions_async(view, prefix, locations, len(javascript_completions_thread_list)+1), thread_name="JavaScriptEnhancementsCompletions"))
85+
86+
# sublime.set_timeout_async(
87+
# lambda: self.on_query_completions_async(
88+
# view, prefix, locations
89+
# )
90+
# )
8391

8492
if not self.completions_ready or not self.completions:
8593
return ([], sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
8694

87-
def on_query_completions_async(self, view, prefix, locations):
95+
def on_query_completions_async(self, view, prefix, locations, index_thread):
8896
self.completions = None
8997

9098
if not view.match_selector(
@@ -177,8 +185,16 @@ def on_query_completions_async(self, view, prefix, locations):
177185
view = sublime.active_window().active_view()
178186
sel = view.sel()[0]
179187
if view.substr(view.word(sel)).strip() :
188+
189+
global javascript_completions_thread_list
190+
191+
if len(javascript_completions_thread_list) == 0 or index_thread+1 < len(javascript_completions_thread_list):
192+
return
193+
180194
self.run_auto_complete()
181195

196+
javascript_completions_thread_list = []
197+
182198
def on_text_command(self, view, command_name, args):
183199
sel = view.sel()[0]
184200
if not view.match_selector(
@@ -215,8 +231,11 @@ def on_selection_modified_async(self, view) :
215231
locations = list()
216232
locations.append(selections[0].begin())
217233

218-
sublime.set_timeout_async(
219-
lambda: self.on_query_completions_async(
220-
view, "", locations
221-
)
222-
)
234+
global javascript_completions_thread_list
235+
236+
javascript_completions_thread_list.append(Util.create_and_start_thread(target=lambda: self.on_query_completions_async(view, "", locations, len(javascript_completions_thread_list)+1), thread_name="JavaScriptEnhancementsCompletions"))
237+
# sublime.set_timeout_async(
238+
# lambda: self.on_query_completions_async(
239+
# view, "", locations
240+
# )
241+
# )

make/_init.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ def init(self):
7575
if result[0]:
7676
sublime.active_window().status_message("JavaScript Enhancements - npm dependencies installed correctly.")
7777
else:
78+
print(result)
7879
if os.path.exists(node_modules_path):
7980
shutil.rmtree(node_modules_path)
80-
sublime.error_message("Error during installation: can not install the npm dependencies for JavaScript Enhancements.")
81+
sublime.error_message("Error during installation: can't install npm dependencies for JavaScript Enhancements plugin.\n\nThe error COULD be caused by the npm permission access (EACCES error), so in this case you need to repair/install node.js and npm in way that doesn't require \"sudo\" command.\n\nFor example you could use a Node Version Manager, such as \"nvm\" or \"nodenv\".\n\nTry to run \"npm install\" inside the package of this plugin to see what you get.")
8182
# else:
8283
# result = npm.update_all()
8384
# if not result[0]:

messages.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"install": "changelog/install.txt",
33
"0.1.0": "changelog/0.1.0.txt",
44
"0.1.01": "changelog/0.1.01.txt",
5-
"0.1.10": "changelog/0.1.10.txt"
5+
"0.1.10": "changelog/0.1.10.txt",
6+
"0.1.11": "changelog/0.1.11.txt"
67
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"caption": "Tools", "id": "tools", "children": [{"caption": "Npm/Yarn Scripts", "id": "npm_scripts", "children": []}]}]
1+
[{"children": [{"children": [], "caption": "Npm/Yarn Scripts", "id": "npm_scripts"}], "caption": "Tools", "id": "tools"}]

0 commit comments

Comments
 (0)