Code Monkey home page Code Monkey logo

Comments (18)

 avatar commented on August 24, 2024 1

thank you my friend for posting this

from sublime-crystal.

oprypin avatar oprypin commented on August 24, 2024 1

What a mess...
Please try #43

from sublime-crystal.

oprypin avatar oprypin commented on August 24, 2024 1

Needs exit = proc.returncode

from sublime-crystal.

 avatar commented on August 24, 2024

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.

faustinoaq avatar faustinoaq commented on August 24, 2024

@girng Looks like you should use pipe = open(os.devnull, 'w') instead, see:

https://github.com/coin-or/pulp/blob/bac6d9d2214ba773d638d2de5149940cfd711359/src/pulp/solvers.py#L376

from sublime-crystal.

 avatar commented on August 24, 2024

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.

faustinoaq avatar faustinoaq commented on August 24, 2024

@girng Try proc = [settings.get("crystal_cmd"), "tool", "format", "-", "--format", "json"]

from sublime-crystal.

 avatar commented on August 24, 2024

@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.

 avatar commented on August 24, 2024

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.

faustinoaq avatar faustinoaq commented on August 24, 2024

@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.

 avatar commented on August 24, 2024

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.

faustinoaq avatar faustinoaq commented on August 24, 2024

@oprypin Thank you! 😅

from sublime-crystal.

 avatar commented on August 24, 2024

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.

 avatar commented on August 24, 2024

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.

 avatar commented on August 24, 2024

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.

 avatar commented on August 24, 2024

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.

faustinoaq avatar faustinoaq commented on August 24, 2024

@girng No problem, keep trying, Thank you for be aware of this issue 👍

from sublime-crystal.

 avatar commented on August 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.