Dan2552 / SublimeTextSwiftAutocomplete

Swift autocompletion in Sublime Text using SourceKitten
MIT License
155 stars 7 forks source link

Installation #15

Closed rudedogg closed 7 years ago

rudedogg commented 7 years ago

Hey, I have sourcekitten installed via homebrew, and running sourcekitten in a shell works.

I'm getting this in the Sublime Console though:

reloading plugin SourceKittenSubl.subl
plugins loaded
Package Control: Skipping automatic upgrade, last run at 2017-01-09 11:59:13, next run at 2017-01-09 12:59:13 or after
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 591, in on_query_completions
    res = callback.on_query_completions(v, prefix, locations)
  File "/Users/rudedogg/Library/Application Support/Sublime Text 3/Packages/SourceKittenSubl/subl.py", line 18, in on_query_completions
    suggestions = subl_source_kitten.complete(offset, file, project_directory, text)
  File "/Users/rudedogg/Library/Application Support/Sublime Text 3/Packages/SourceKittenSubl/dependencies/../src/subl_source_kitten.py", line 16, in complete
    collection = source_kitten.complete(offset, file, project_directory, text)
  File "/Users/rudedogg/Library/Application Support/Sublime Text 3/Packages/SourceKittenSubl/dependencies/../src/source_kitten.py", line 25, in complete
    return _execute(cmd, _json_parse)
  File "/Users/rudedogg/Library/Application Support/Sublime Text 3/Packages/SourceKittenSubl/dependencies/../src/source_kitten.py", line 86, in _execute
    return _execute_cached("§§§".join(cmd), result_handler)
  File "./python3.3/functools.py", line 275, in wrapper
  File "/Users/rudedogg/Library/Application Support/Sublime Text 3/Packages/SourceKittenSubl/dependencies/../src/source_kitten.py", line 92, in _execute_cached
    with Popen(cmd, stdout=PIPE, stderr=PIPE) as p:
  File "./python3.3/subprocess.py", line 819, in __init__
  File "./python3.3/subprocess.py", line 1448, in _execute_child
FileNotFoundError: [Errno 2] No such file or directory: 'sourcekitten'

Did I go wrong somewhere?

rudedogg commented 7 years ago

Did a little searching and found this: http://stackoverflow.com/questions/18855932/file-not-found-error-when-running-local-binary-with-popen

Changing line 18 of source_kitten.py to "/usr/local/bin/sourcekitten" did the trick.

Dan2552 commented 7 years ago

Sorry for not responding sooner, I thought I had emails enabled for notifications.

I wonder why I don't get this issue... Is /usr/local/bin in your shell $PATH variable (run echo $PATH to check)? And do you launch Sublime Text from command line?

rudedogg commented 7 years ago

@Dan2552 No problem! Awesome package - it is the most promising Swift completion I've found. I'm looking forward to the improvements you have in the issue queue!

Is /usr/local/bin in your shell $PATH variable

Yes I have /usr/local/bin in the echo $PATH output.

And do you launch Sublime Text from command line?

No, I just use the dock. I tried it from the command line just to check - and get the FileNotFoundError: [Errno 2] No such file or directory: 'sourcekitten' error.

Looking at the subprocess docs using Shell=True would be a workaround and make use of my '$PATH'. But it looks like there are security issues - not sure if they're worth worrying about? Using the default homebrew path and adding a setting for using a different/custom path seems like a safe/clean option.

dielsonsales commented 7 years ago

@rudedogg You mean changing this:

calculated_offset = _calculate_source_kitten_compatible_offset(offset, text)

to this?

calculated_offset = "/usr/local/bin/sourcekitten"
Dan2552 commented 7 years ago

@dielsonsales the line numbers have probably changed a bit

Give this a go: https://github.com/Dan2552/SourceKittenSubl/blob/master/src/source_kitten.py#L23

-        "sourcekitten",
+        "/usr/local/bin/sourcekitten",
dielsonsales commented 7 years ago

Thanks! It's working now.

Dan2552 commented 7 years ago

This should be resolved in https://github.com/Dan2552/SourceKittenSubl/pull/22