jcberquist / sublimetext-cfml

CFML (ColdFusion and Lucee) package for Sublime Text
MIT License
115 stars 24 forks source link

cfml_completion_docs setting is being ignored #112

Closed kevindb closed 6 years ago

kevindb commented 6 years ago

Thank you for making this plugin. It makes ColdFusion development in Sublime Text sooooo much easier.

I am using the sublimetext-cfml v0.26.10 with Sublime Text 3.0 build 3143 on Windows 7. My corporate network blocks network requests that don't go through the corporate proxy, including requests sublimetext-cfml makes to cfdocs.org.

My User/cfml_package.sublime-settings file has both of the docs settings turned off:

{
    "cfml_hover_docs": false,
    "cfml_completion_docs": false
}

However, the entire Sublime Text application still freezes up for about 20 seconds when I am editing a CF function (tags do not cause a problem). When a freeze occurs, this is the error in my console:

Traceback (most recent call last):
  File "./python3.3/urllib/request.py", line 1248, in do_open
  File "./python3.3/http/client.py", line 1065, in request
  File "./python3.3/http/client.py", line 1103, in _send_request
  File "./python3.3/http/client.py", line 1061, in endheaders
  File "./python3.3/http/client.py", line 906, in _send_output
  File "./python3.3/http/client.py", line 844, in send
  File "./python3.3/http/client.py", line 1198, in connect
  File "./python3.3/socket.py", line 435, in create_connection
  File "./python3.3/socket.py", line 426, in create_connection
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 591, in on_query_completions
    res = callback.on_query_completions(v, prefix, locations)
  File "C:\Users\EPARYJ6\AppData\Roaming\Sublime Text 3\Packages\sublimetext-cfml-master\cfml_plugin.py", line 54, in on_query_completions
    return completions.get_completions(view, locations[0], prefix)
  File "C:\Users\EPARYJ6\AppData\Roaming\Sublime Text 3\Packages\sublimetext-cfml-master\src\completions.py", line 28, in get_completions
    completionlist = callback(cfml_view)
  File "C:\Users\EPARYJ6\AppData\Roaming\Sublime Text 3\Packages\sublimetext-cfml-master\src\basecompletions\__init__.py", line 12, in get_completions
    return basecompletions.get_script_completions(cfml_view)
  File "C:\Users\EPARYJ6\AppData\Roaming\Sublime Text 3\Packages\sublimetext-cfml-master\src\basecompletions\basecompletions.py", line 55, in get_script_completions
    param_completions = get_param_completions(cfml_view)
  File "C:\Users\EPARYJ6\AppData\Roaming\Sublime Text 3\Packages\sublimetext-cfml-master\src\basecompletions\basecompletions.py", line 174, in get_param_completions
    data, success = cfdocs.get_cfdoc(cfml_view.function_call_params.function_name)
  File "C:\Users\EPARYJ6\AppData\Roaming\Sublime Text 3\Packages\sublimetext-cfml-master\src\cfdocs\cfdocs.py", line 93, in get_cfdoc
    return fetch_cfdoc(function_or_tag)
  File "C:\Users\EPARYJ6\AppData\Roaming\Sublime Text 3\Packages\sublimetext-cfml-master\src\cfdocs\cfdocs.py", line 132, in fetch_cfdoc
    json_string = urllib.request.urlopen(full_url).read().decode("utf-8")
  File "./python3.3/urllib/request.py", line 156, in urlopen
  File "./python3.3/urllib/request.py", line 469, in open
  File "./python3.3/urllib/request.py", line 487, in _open
  File "./python3.3/urllib/request.py", line 447, in _call_chain
  File "./python3.3/urllib/request.py", line 1289, in https_open
  File "./python3.3/urllib/request.py", line 1251, in do_open
urllib.error.URLError: <urlopen error [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond>

I suspect the cfml_completion_docs setting is being ignored and a request to cfdocs.org is still being attempted. Is there another docs setting I should turn off in order to prevent the package from making requests to cfdocs.org?

As a short-term fix, I have changed src/cfdocs/cfdocs.py Line 93 from

return fetch_cfdoc(function_or_tag)

to

return None

This has "fixed" the freezing issue, but I'm sure it's not an ideal solution. When I do edit a CF function, I get the following error in console (although the application does not freeze):

Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 591, in on_query_completions
    res = callback.on_query_completions(v, prefix, locations)
  File "C:\Users\EPARYJ6\AppData\Roaming\Sublime Text 3\Packages\sublimetext-cfml-master\cfml_plugin.py", line 54, in on_query_completions
    return completions.get_completions(view, locations[0], prefix)
  File "C:\Users\EPARYJ6\AppData\Roaming\Sublime Text 3\Packages\sublimetext-cfml-master\src\completions.py", line 28, in get_completions
    completionlist = callback(cfml_view)
  File "C:\Users\EPARYJ6\AppData\Roaming\Sublime Text 3\Packages\sublimetext-cfml-master\src\basecompletions\__init__.py", line 12, in get_completions
    return basecompletions.get_script_completions(cfml_view)
  File "C:\Users\EPARYJ6\AppData\Roaming\Sublime Text 3\Packages\sublimetext-cfml-master\src\basecompletions\basecompletions.py", line 55, in get_script_completions
    param_completions = get_param_completions(cfml_view)
  File "C:\Users\EPARYJ6\AppData\Roaming\Sublime Text 3\Packages\sublimetext-cfml-master\src\basecompletions\basecompletions.py", line 174, in get_param_completions
    data, success = cfdocs.get_cfdoc(cfml_view.function_call_params.function_name)
TypeError: 'NoneType' object is not iterable

I'm sorry I can't write a real Pull Request to help address this issue, but I don't know Python at all.

Thank you

jcberquist commented 6 years ago

Thanks for the detailed report. The issue happens when the package tries to load completions for built in function parameters. Those are loaded from cfdocs data and it seems I don't currently have a way to turn them off. I will add a setting so that they can be disabled.

You may have seen this in the docs but if you can access the cfdocs repository on github and clone it locally, you can point this package to the local copy of the data folder (https://github.com/foundeo/cfdocs/tree/master/data/en) using the setting cfdocs_path (e.g. "cfdocs_path": "C:/github/cfdocs/data/en/"). With that in place no network requests will be made to the cfdocs.org repository.

Either way, I will add a setting to disable the network requests.

jcberquist commented 6 years ago

Incidentally, that return None you edited is supposed to return a tuple, which is why you are still seeing an error after editing it - you could try return None, False instead.

kevindb commented 6 years ago

Haha, yeah, I did see the option to download a local copy of cfdocs. My company also doesn't like us cloning repos or downloading compressed ZIP files. I'm not all that interested in the autocomplete feature, so it didn't seem worth the fight with IT to download a copy of cfdocs.

I really appreciate your willingness to add an option to disable the network requests. It'll make things a lot easier for my team here.

Thank you again!

kevindb commented 6 years ago

you could try return None, False instead

You are my hero! This change worked perfectly (for the limited purpose of canceling all the network requests). I'm not longer getting the errors in the console.

jcberquist commented 6 years ago

I have added a setting "cfdocs_enabled" to the package settings which you can set to false to disable the cfdocs integration.