Comments (18)
thank you my friend for posting this
from sublime-crystal.
What a mess...
Please try #43
from sublime-crystal.
Needs exit = proc.returncode
from sublime-crystal.
hi, thx for support again.
i got
NameError: global name 'pipe' is not defined
so i changed the pipe
to subprocess.PIPE
, error went away.
but now, am getting:
NameError: global name 'proc' is not defined
on line 33
this is line 33:
proc.stdin.write(bytes(src, 'UTF-8'))
from sublime-crystal.
@girng Looks like you should use pipe = open(os.devnull, 'w')
instead, see:
from sublime-crystal.
thank you, @faustinoaq did that. got rid of the pipe error, now still get:
NameError: global name 'proc' is not defined
line 38, in run
line 38:
proc.stdin.write(bytes(src, 'UTF-8'))
from sublime-crystal.
@girng Try proc = [settings.get("crystal_cmd"), "tool", "format", "-", "--format", "json"]
from sublime-crystal.
@faustinoaq ty again sir.. sorry for all this trouble.. lol
that error went away, but now getting:
AttributeError: 'list' object has no attribute 'stdin'
in line 39:
proc.stdin.write(bytes(src, 'UTF-8'))
from sublime-crystal.
top part of def run:
def run(self, edit):
vsize = self.view.size()
region = sublime.Region(0, vsize)
src = self.view.substr(region)
window = self.view.window()
settings = sublime.load_settings('Crystal.sublime-settings')
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
pipe = open(os.devnull, 'w')
# Prevent flashing windows if used from a GUI application
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
proc = [settings.get("crystal_cmd"), "tool", "format", "-", "--format", "json"]
rc = subprocess.call([settings.get("crystal_cmd"), "tool", "format", "-", "--format", "json"], stdout = pipe, stderr = pipe,startupinfo = startupinfo)
proc.stdin.write(bytes(src, 'UTF-8'))
proc.stdin.close()
output = proc.stdout.read().decode('UTF-8')
exit = proc.wait()
pos = 0
from sublime-crystal.
@girng no problem 😅
Try this:
def run(self, edit):
vsize = self.view.size()
region = sublime.Region(0, vsize)
src = self.view.substr(region)
window = self.view.window()
settings = sublime.load_settings('Crystal.sublime-settings')
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
pipe = open(os.devnull, 'w')
# Prevent flashing windows if used from a GUI application
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
cmd = [settings.get("crystal_cmd"), "tool", "format", "-", "--format", "json"]
proc = subprocess.call(cmd, stdout = pipe, stderr = pipe,startupinfo = startupinfo)
proc.stdin.write(bytes(src, 'UTF-8'))
proc.stdin.close()
output = proc.stdout.read().decode('UTF-8')
exit = proc.wait()
pos = 0
# more code...
or this:
def run(self, edit):
vsize = self.view.size()
region = sublime.Region(0, vsize)
src = self.view.substr(region)
window = self.view.window()
settings = sublime.load_settings('Crystal.sublime-settings')
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
pipe = open(os.devnull, 'w')
# Prevent flashing windows if used from a GUI application
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
cmd = [settings.get("crystal_cmd"), "tool", "format", "-", "--format", "json"]
with subprocess.call(cmd, stdout = pipe, stderr = pipe,startupinfo = startupinfo) as proc:
proc.stdin.write(bytes(src, 'UTF-8'))
proc.stdin.close()
output = proc.stdout.read().decode('UTF-8')
exit = proc.wait()
pos = 0
# more code...
from sublime-crystal.
ty for continuing to help. this is painful xD
first code u supplied, i get:
AttributeError: 'int' object has no attribute 'stdin'
line 39:
proc.stdin.write(bytes(src, 'UTF-8'))
2nd code u supplied, i get:
return self.run(edit)
File "crystal_format in C:\Users\Administrator\AppData\Roaming\Sublime Text 3\Installed Packages\Crystal.sublime-package", line 38, in run
AttributeError: __exit__
line 38:
with subprocess.call(cmd, stdout = pipe, stderr = pipe,startupinfo = startupinfo) as proc:
from sublime-crystal.
@oprypin Thank you! 😅
from sublime-crystal.
File "crystal_format in C:\Users\Administrator\AppData\Roaming\Sublime Text 3\Installed Packages\Crystal.sublime-package", line 45, in run
NameError: global name 'exit' is not defined
line 45:
if exit == 0:
from sublime-crystal.
ok, so i commented out the if exit == 0 block (got rid of that error). however, it still doesn't format the code :(
sorry for all the trouble, im just trying reporting back if errors are found
from sublime-crystal.
ok. got it working
def run(self, edit):
vsize = self.view.size()
region = sublime.Region(0, vsize)
src = self.view.substr(region)
window = self.view.window()
settings = sublime.load_settings('Crystal.sublime-settings')
command = [settings.get("crystal_cmd"), "tool", "format", "-", "--format", "json"]
popen_args = dict(args=command, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
# Prevent flashing terminal windows
if sys.platform.startswith('win'):
popen_args['startupinfo'] = subprocess.STARTUPINFO()
popen_args['startupinfo'].dwFlags |= subprocess.STARTF_USESHOWWINDOW
with subprocess.Popen(**popen_args) as proc:
output, _ = proc.communicate(src.encode('utf-8'))
output = output.decode('utf-8')
pos = 0
if not self.has_redo():
for op, text in diff_match_patch().diff_main(src, output):
if op == diff_match_patch.DIFF_DELETE:
self.view.erase(edit, sublime.Region(pos, pos + len(text)))
if op == diff_match_patch.DIFF_INSERT:
self.view.insert(edit, pos, text)
pos += len(text)
if op == diff_match_patch.DIFF_EQUAL:
pos += len(text)
self.view.erase_regions('crystal_errors')
window.run_command("hide_panel")
else:
error = json.loads(output)
error_pos = self.view.text_point(error[0]["line"] - 1, error[0]["column"] - 1)
line_region = self.view.full_line(error_pos)
self.view.add_regions('crystal_errors', [line_region], 'comment', 'dot', sublime.HIDDEN)
error_panel = window.create_output_panel('crystal_errors')
error_panel.run_command("append", {"characters":
"Error at line %d, column %d: %s" % (error[0]["line"], error[0]["column"], error[0]['message'])
})
window.run_command("show_panel", {"panel": "output.crystal_errors"})
i basically just removed the if exit == 0:
from oprypin's code
from sublime-crystal.
WARNING
DO NOT REMOVE that if exit == 0
I just saved, and randomly almost LOST my entire LoginHandler.cr file (it replaced my file with blank text). Doing a back up right now and going back to the original crystal_format.py with the cmd pop up for now. Not risking anything atm sorry
from sublime-crystal.
@girng No problem, keep trying, Thank you for be aware of this issue 👍
from sublime-crystal.
Praise to you and opryprin for help. just need solution for global name 'exit' is not defined
and this can finally be solved!!
from sublime-crystal.
Related Issues (20)
- Support for flat rescue/ensure/else block in do/end block HOT 3
- Update package control HOT 1
- `:!` and `:!=` are considered operators rather than Symbols
- `__END_LINE__` is not scoped as a a magic constant.
- Auto format doesn't respect sublime indentation settings HOT 3
- Octal literals have no scope applied to them HOT 1
- Avoid always applying `primary.control` scope to `type` HOT 1
- Strange jQuery error in my logs when switching to Crystal language
- Support for ECR HOT 2
- code randomly gets cut off on save
- Add "verbatim" highlighting HOT 1
- Free variable formatting
- Add `entity.name` scopes to property definitions
- `annotation` highlight
- Proper `self?` highlighting
- Crystal 0.27.1 does not work HOT 3
- Change formatter output format from JSON to plain text
- HEREDOCs with HTML tags in them breaks syntax highlighting
- Syntax highlighting does not work correctly for generic types in function parameters
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sublime-crystal.