Skip to content

Commit

Permalink
trying to fix Autocompletion tooltip stuttering
Browse files Browse the repository at this point in the history
  • Loading branch information
pichillilorenzo committed Jan 3, 2018
1 parent c2cc24e commit d9f5780
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 31 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

This is in **Beta** version for testing.
This is in **BETA** version for **testing**.

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

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

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

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

Expand Down Expand Up @@ -69,7 +69,7 @@ Manually:

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.

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`:
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`:

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

Email me for any questions or doubts about this project on: [[email protected]](mailto:[email protected])

### Issues

For any problems, open an issue with the Sublime Text console logs please!

### Feature request/enhancement

For feature requests or them enhancement, please open an issue with the corresponding label.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1230,9 +1230,10 @@ def init(self):
if result[0]:
sublime.active_window().status_message("JavaScript Enhancements - npm dependencies installed correctly.")
else:
print(result)
if os.path.exists(node_modules_path):
shutil.rmtree(node_modules_path)
sublime.error_message("Error during installation: can not install the npm dependencies for JavaScript Enhancements.")
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.")
# else:
# result = npm.update_all()
# if not result[0]:
Expand Down Expand Up @@ -2976,6 +2977,10 @@ def get(self, key):
import sublime, sublime_plugin
import os, tempfile

# list of threads that are used to check if there are
# multiple async completions tooltip queued (fix for tooltip stuttering)
javascript_completions_thread_list = []

def build_type_from_func_details(comp_details):
if comp_details :

Expand Down Expand Up @@ -3029,7 +3034,7 @@ def run_auto_complete(self):

def on_query_completions(self, view, prefix, locations):
# Return the pending completions and clear them

#
if not view.match_selector(
locations[0],
'source.js - string - comment'
Expand All @@ -3050,16 +3055,20 @@ def on_query_completions(self, view, prefix, locations):
self.completions_ready = False
return self.completions

sublime.set_timeout_async(
lambda: self.on_query_completions_async(
view, prefix, locations
)
)
global javascript_completions_thread_list

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"))

# sublime.set_timeout_async(
# lambda: self.on_query_completions_async(
# view, prefix, locations
# )
# )

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

def on_query_completions_async(self, view, prefix, locations):
def on_query_completions_async(self, view, prefix, locations, index_thread):
self.completions = None

if not view.match_selector(
Expand Down Expand Up @@ -3152,8 +3161,16 @@ def on_query_completions_async(self, view, prefix, locations):
view = sublime.active_window().active_view()
sel = view.sel()[0]
if view.substr(view.word(sel)).strip() :

global javascript_completions_thread_list

if len(javascript_completions_thread_list) == 0 or index_thread+1 < len(javascript_completions_thread_list):
return

self.run_auto_complete()

javascript_completions_thread_list = []

def on_text_command(self, view, command_name, args):
sel = view.sel()[0]
if not view.match_selector(
Expand Down Expand Up @@ -3190,11 +3207,14 @@ def on_selection_modified_async(self, view) :
locations = list()
locations.append(selections[0].begin())

sublime.set_timeout_async(
lambda: self.on_query_completions_async(
view, "", locations
)
)
global javascript_completions_thread_list

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"))
# sublime.set_timeout_async(
# lambda: self.on_query_completions_async(
# view, "", locations
# )
# )


import sublime, sublime_plugin
Expand Down
79 changes: 79 additions & 0 deletions changelog/0.1.11.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
v0.1.11

## Fixes

- Trying to fix "Autocompletion tooltip stutters" #5


=================================================================
** THIS PLUGIN IS IN BETA! Thanks for your support in advance! **
=================================================================

If you like it, remember to star it ⭐ on GitHub: https://github.com/pichillilorenzo/JavaScriptEnhancements

** USAGE **
===========

See how it works on the Wiki: 👉👉 https://github.com/pichillilorenzo/JavaScriptEnhancements/wiki 👈👈


** WHAT IS THIS? **
===================

This plugin uses Flow (javascript static type checker from Facebook) under the hood.

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

- Cordova projects (run cordova emulate, build, compile, serve, etc. directly from Sublime Text!)
- Ionic v1 and v2 projects (same as Cordova projects!)
- Angular v1 and v2 projects
- React projects
- Express projects
- Yeoman generators
- Local bookmarks project
- JavaScript real-time errors
- etc.

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

It turns Sublime Text into a JavaScript IDE like!

This project is based on my other Sublime Text plugin JavaScript Completions (https://github.com/pichillilorenzo/JavaScript-Completions)

** NOTE **
If you want use this plugin, you may want uninstall/disable the JavaScript Completions plugin, if installed.

** OS SUPPORTED NOW **
======================

👉 Linux (64-bit)
👉 Mac OS X

❗❗ Dependencies ❗❗
=======================

In order to work properly, this plugin has some dependencies:

👉 Sublime Text 3 (build 3124 or newer)
👉 Node.js and npm (https://nodejs.org or nvm (https://github.com/creationix/nvm))
👉 TerminalView sublime text plugin (https://github.com/Wramberg/TerminalView)

Not required, but useful for typescript files (Flow wont work on this type of files):

👉 TypeScript sublime text plugin (https://github.com/Microsoft/TypeScript-Sublime-Plugin)

** Flow Requirements **
=======================

It use [Flow](https://github.com/facebook/flow) for type checking and auto-completions.

👉 Mac OS X
👉 Linux (64-bit)
👉 Windows (64-bit)

Email me for any questions or doubts about this new project on: [email protected]

Thanks for your support! 😄😄

MIT License
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import sublime, sublime_plugin
import os, tempfile

# list of threads that are used to check if there are
# multiple async completions tooltip queued (fix for tooltip stuttering)
javascript_completions_thread_list = []

def build_type_from_func_details(comp_details):
if comp_details :

Expand Down Expand Up @@ -54,7 +58,7 @@ def run_auto_complete(self):

def on_query_completions(self, view, prefix, locations):
# Return the pending completions and clear them

#
if not view.match_selector(
locations[0],
'source.js - string - comment'
Expand All @@ -75,16 +79,20 @@ def on_query_completions(self, view, prefix, locations):
self.completions_ready = False
return self.completions

sublime.set_timeout_async(
lambda: self.on_query_completions_async(
view, prefix, locations
)
)
global javascript_completions_thread_list

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"))

# sublime.set_timeout_async(
# lambda: self.on_query_completions_async(
# view, prefix, locations
# )
# )

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

def on_query_completions_async(self, view, prefix, locations):
def on_query_completions_async(self, view, prefix, locations, index_thread):
self.completions = None

if not view.match_selector(
Expand Down Expand Up @@ -177,8 +185,16 @@ def on_query_completions_async(self, view, prefix, locations):
view = sublime.active_window().active_view()
sel = view.sel()[0]
if view.substr(view.word(sel)).strip() :

global javascript_completions_thread_list

if len(javascript_completions_thread_list) == 0 or index_thread+1 < len(javascript_completions_thread_list):
return

self.run_auto_complete()

javascript_completions_thread_list = []

def on_text_command(self, view, command_name, args):
sel = view.sel()[0]
if not view.match_selector(
Expand Down Expand Up @@ -215,8 +231,11 @@ def on_selection_modified_async(self, view) :
locations = list()
locations.append(selections[0].begin())

sublime.set_timeout_async(
lambda: self.on_query_completions_async(
view, "", locations
)
)
global javascript_completions_thread_list

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"))
# sublime.set_timeout_async(
# lambda: self.on_query_completions_async(
# view, "", locations
# )
# )
3 changes: 2 additions & 1 deletion make/_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ def init(self):
if result[0]:
sublime.active_window().status_message("JavaScript Enhancements - npm dependencies installed correctly.")
else:
print(result)
if os.path.exists(node_modules_path):
shutil.rmtree(node_modules_path)
sublime.error_message("Error during installation: can not install the npm dependencies for JavaScript Enhancements.")
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.")
# else:
# result = npm.update_all()
# if not result[0]:
Expand Down
3 changes: 2 additions & 1 deletion messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"install": "changelog/install.txt",
"0.1.0": "changelog/0.1.0.txt",
"0.1.01": "changelog/0.1.01.txt",
"0.1.10": "changelog/0.1.10.txt"
"0.1.10": "changelog/0.1.10.txt",
"0.1.11": "changelog/0.1.11.txt"
}
2 changes: 1 addition & 1 deletion project/npm/Main_disabled.sublime-menu
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"caption": "Tools", "id": "tools", "children": [{"caption": "Npm/Yarn Scripts", "id": "npm_scripts", "children": []}]}]
[{"children": [{"children": [], "caption": "Npm/Yarn Scripts", "id": "npm_scripts"}], "caption": "Tools", "id": "tools"}]

0 comments on commit d9f5780

Please sign in to comment.