Dan2552 / SublimeTextSwiftAutocomplete

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

UnicodeEncodeError: 'ascii' codec can't encode character '\xa9' in position 84 #18

Closed franciscolourenco closed 6 years ago

franciscolourenco commented 7 years ago
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 389, in run_callback
    expr()
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 620, in <lambda>
    run_callback('on_hover', callback, lambda: callback.on_hover(v, point, hover_zone))
  File "/Users/user/Library/Application Support/Sublime Text 3/Packages/SourceKittenSubl/subl.py", line 35, in on_hover
    text = subl_source_kitten.popup(point, file, project_directory, text)
  File "/Users/user/Library/Application Support/Sublime Text 3/Packages/SourceKittenSubl/dependencies/../src/subl_source_kitten.py", line 22, in popup
    output = source_kitten.cursor_info(offset, file, project_directory, text)
  File "/Users/user/Library/Application Support/Sublime Text 3/Packages/SourceKittenSubl/dependencies/../src/source_kitten.py", line 49, in cursor_info
    tmp_file = _create_temp_file(text)
  File "/Users/user/Library/Application Support/Sublime Text 3/Packages/SourceKittenSubl/dependencies/../src/source_kitten.py", line 163, in _create_temp_file
    text_file.write(text)
UnicodeEncodeError: 'ascii' codec can't encode character '\xa9' in position 84: ordinal not in range(128)
Dan2552 commented 7 years ago

@aristidesfl Is there any chance you could send over a source file that you have this issue on? I'm failing to reproduce this even when saving files in different encodings. \xa9 as far as I can work out is a copyright symbol.

You shouldn't need to share any real code, something similar to this should be enough:

// This file is saved with ??? encoding
// and has a problematic symbol: ©

let abc = "hello"

Hopefully with that I can write a failing spec to fix against 😄

franciscolourenco commented 7 years ago

Keyboard.zip

I'm not sure it is a problem with this file specifically.

EDIT: also noticed indexing: crawldb not available, indexing abandoned not sure if it is related to this plugin though..

Dan2552 commented 7 years ago

The file works for me so indeed it mustn't be an issue with the file specifically then.

That indexing error definitely doesn't sound related to this plugin.

Are there any encoding specific settings in your preferences file?

Do the specs pass for you? Under the plugin directory run the run_tests script - it might require you first install python3 (brew install python3)

franciscolourenco commented 7 years ago

Error is being thrown by the plugin, its shown in the error. Tests pass:

user at unknown in ~/code/SourceKittenSubl on master
$ run_tests
........source_kitten.complete - Performance test (1st):  7207 ms
source_kitten.complete - Performance test (2nd):  32 ms
........subl_source_kitten.complete_with_haste - Performance test:  1006 ms
....
----------------------------------------------------------------------
Ran 20 tests in 11.770s

OK
..
----------------------------------------------------------------------
Ran 2 tests in 0.491s

OK

PS: Tests don't run if current directory contains spaces, like "/Application Support/Sublime..."

Dan2552 commented 7 years ago

That indexing error definitely doesn't sound related to this plugin.

I was referring to indexing: crawldb not available, indexing abandoned


Ok... That's good to see the tests pass I guess. Suggests something is different between our Sublime Text setups affecting it.

Could you paste in your preferences file? Might also be worth checking any other plugins you have installed but I'm not sure how's best to check them without uninstalling them 1 by 1 which I'd understand if you didn't want to do that.


(re ps: cheers, guess I never tried 😊 I'll log it)

nettlep commented 6 years ago

This issue should be fixed in 08d213e (one of the commits from PR #26.)

The solution was to convert to UTF-8 and store the temporary file as binary.