akalongman / sublimetext-codeformatter

Code Formatter plugin for ST2/ST3
MIT License
772 stars 130 forks source link

Doesn't recognize type of file #15

Closed ltribolet closed 10 years ago

ltribolet commented 11 years ago

I'm on Windows 7 x86 with ST3

When I first try to format a PHP file it throws me an error :

Formatter for this file type (text) not found.

And then if I attempt to format again all the code is collapsed.

Any idea ?

ltribolet commented 11 years ago

I reinstalled all components (upgraded php to 5.4, reinstalled PEAR and PHP beautifier), checked that PHP_Beautifier was ok by testing in command line.

So now I have a problem :

Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 549, in run_
    return self.run(edit)
  File "C:\Users\luc.tribolet\AppData\Roaming\Sublime Text 3\Packages\CodeFormatter\code_formatter.py", line 60, in run
    stdout, stderr = formatter.format(file_text_utf)
  File "C:\Users\luc.tribolet\AppData\Roaming\Sublime Text 3\Packages\CodeFormatter\codeformatter\formatter.py", line 62, in format
    return self.clean(stdout), self.clean(stderr)
  File "C:\Users\luc.tribolet\AppData\Roaming\Sublime Text 3\Packages\CodeFormatter\codeformatter\formatter.py", line 83, in clean
    string = string.decode('UTF-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x82 in position 96: invalid start byte

So as I don't know any of Python I can't go further but it seems due that I'm on a 32 bits machine, I don't have 64 one to confirm.

ltribolet commented 11 years ago

Ok back to square one. I resolved this problem I had an error with some special caracters shouted from the OS ( as "é") it couldn't find php_beautifier.bat I restarted Sublime Text and it was good.

So now I still have this issue :

error: CodeFormatter

Formatter for this file type (text) not found.
hobocta commented 10 years ago

@ltribolet I have similar problem https://github.com/akalongman/sublimetext-codeformatter/issues/42 Did you decide this problem?

ltribolet commented 10 years ago

Sadly no. No clue how to solve this. I switched editor and went to PHPStorm which does that natively without any problems. I know this not a real solution but after struggling many times with PHP plugins on ST3 I decided to switch.

akalongman commented 10 years ago

I want fix it but need your help. On my machine everything works OK. Help me find bug, sent me more information about your file, os, ST version, PHP version, CodeFormatter version

ltribolet commented 10 years ago

I don't know if I'll be able to reproduce since I changed computer. But I'll try to reproduce it on my work's machine on Monday :)

hobocta commented 10 years ago

@ltribolet I understand you, PhpStorm is really one of the ways, but I do not like yet. I'll wait for your checking on work machine. Thank you! :)

@akalongman It is great! I am ready to provide all necessary information.

OS - Windows 7, x64, SP3. 2014-01-25_14-28-52

ST3, build 3059. 2014-01-25_14-25-20

PHP 5.3.27 (cli) (built: Jul 10 2013 20:36:59) 2014-01-25_14-29-58

PHP info - http://paste.ee/r/gTgTN

CodeFormatter installed by git clone, last version. git log: 2014-01-25_14-33-29

After start SL console looks like this - http://paste.ee/r/NOdRB

When I run command Format Code image in console I see error: image

Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 549, in run_
    return self.run(edit)
  File "C:\Users\Anton\AppData\Roaming\Sublime Text 3\Packages\CodeFormatter\code_formatter.py", line 60, in run
    stdout, stderr = formatter.format(file_text_utf)
  File "C:\Users\Anton\AppData\Roaming\Sublime Text 3\Packages\CodeFormatter\codeformatter\formatter.py", line 62, in format
    return self.clean(stdout), self.clean(stderr)
  File "C:\Users\Anton\AppData\Roaming\Sublime Text 3\Packages\CodeFormatter\codeformatter\formatter.py", line 83, in clean
    string = string.decode('UTF-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xad in position 14: invalid start byte

I tried this operation on clean SL3 with one installed package - codeformatter. The result was the same.

When I add in file codeformatter/phpbeautifier/__init__.py this code: image on run command Format Code in console I see there:

==================
b"<?php\n\n$a = 'string';\n\necho $a;\n\n"
------------------
b''
------------------
b'"".\\php.exe"" \xad\xa5 \xef\xa2\xab\xef\xa5\xe2\xe1\xef \xa2\xad\xe3\xe2\xe0\xa5\xad\xad\xa5\xa9 \xa8\xab\xa8 \xa2\xad\xa5\xe8\xad\xa5\xa9\r\n\xaa\xae\xac\xa0\xad\xa4\xae\xa9, \xa8\xe1\xaf\xae\xab\xad\xef\xa5\xac\xae\xa9 \xaf\xe0\xae\xa3\xe0\xa0\xac\xac\xae\xa9 \xa8\xab\xa8 \xaf\xa0\xaa\xa5\xe2\xad\xeb\xac \xe4\xa0\xa9\xab\xae\xac.\r\n'
==================
Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 549, in run_
    return self.run(edit)
  File "C:\Users\Anton\AppData\Roaming\Sublime Text 3\Packages\CodeFormatter\code_formatter.py", line 60, in run
    stdout, stderr = formatter.format(file_text_utf)
  File "C:\Users\Anton\AppData\Roaming\Sublime Text 3\Packages\CodeFormatter\codeformatter\formatter.py", line 62, in format
    return self.clean(stdout), self.clean(stderr)
  File "C:\Users\Anton\AppData\Roaming\Sublime Text 3\Packages\CodeFormatter\codeformatter\formatter.py", line 83, in clean
    string = string.decode('UTF-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xad in position 14: invalid start byte

Doctor, will I live? :)

hobocta commented 10 years ago

I solved this problem!

I changed variable PHP in file php_beautifier.bat:

--- C:\Program Files (x86)\PHP\php_beautifier.bat
+++ untitled 2
@@ -1,5 +1,6 @@
 @ECHO OFF
-SET PHP=".\php.exe"
+rem SET PHP=".\php.exe"
+SET PHP="php.exe"
 SET BEAUTIFY="c:\Program Files (x86)\PHP"\php_beautifier
 %PHP% -d output_buffering=1 -f %BEAUTIFY% -- %1 %2 %3 %4 %5 %6 %7 %8 %9
 @ECHO ON

and codeformatter work now!

Thank you! :)