ligershark / Kulture

Sublime extension for ASP.NET vNext
Other
236 stars 30 forks source link

"Run K Commands" does nothing #22

Closed elliotec closed 9 years ago

elliotec commented 10 years ago

Mac OSX 10.9.4, Sublime text 3 build 3059. Things are installed properly, Run K Commands shows up in the command list, but hitting return doesn't open a console, doesn't do anything.

sayedihashimi commented 10 years ago

Thanks for the report. I looked into this. Here is what I found. The k_run command code that is invoked when you start "Run K Commands" is at https://github.com/ligershark/Kulture/blob/923b5816b63e32dbe597193e9a3d72024bb870b6/Kulture.py#L169. The relevant code snippet is below

class KRunCommand(sublime_plugin.WindowCommand):

    def run(self):
        if (plat == 'win'):
            file_name = self.window.folders()[0] + '\\project.json'
        else:
            file_name = self.window.folders()[0] + '/project.json'
        try:
            json_file = json.load(open(file_name))
        except IOError:
            print('project.json not found')
            return
        self.commands = []
<other code removed>

This looks like it assumes that the root folder that is opened is contains project.json. If the file is not found then project.json not found is written to the console in sublime. You can activate that with `ctrl+``.

The implementation we have here is not ideal. I think a better implementation would be to take the directory of the file which is being edited and look for project.json. If not found go up until you find a directory which has project.json. When that is found then execute the desired command. We should continue searching until we get to the root directory. If we don't find a project.json by then we throw an error.

Thoughts?

cc @shirhatti

sayedihashimi commented 10 years ago

OK I've made some changes in the master branch to properly search up for project.json. If you invoke the command from a file that is not in the same folder as project.json today you'll get an error when it tries to invoke the command. I'm going to add a new issue to track that. I think the resolution to that is to set the working directory to the folder that has project.json or pass the path to the folder as an arg to the script and have the script cd to that folder.

If you have a change please try out changes in master branch and let me know if you run into any issues other than what I have noted above.

sayedihashimi commented 10 years ago

I have created issue #23 to track the issue I mentioned above.

FYI I'm not a python expert so if anyone sees issues with my code please do send a PR to fix up any errors/bad practices. Don't worry I will get better over time :)

elliotec commented 10 years ago

Awesome, thanks for the quick and thorough response. Checking it out now!

sayedihashimi commented 10 years ago

OK I think I have things working now. Before calling the script it will search up for the directory that contains project.json and then execute it from that directory. The work is in the master branch. Can you try it out? The easiest way is try it is to clone the Kulture repo into the Sublime Packages folder. See manual install on the readme.

Once this has been verified by a few people I will merge it to Release so that the extension is updated. I'd like to hear from users on Mac, Windows & Linux if possible.

Help Needed

As I stated previously I'm new to python so it will take some time for me to get up to speed. In the mean time I'm going to do the best implementation that I can and ask for help when needed. Now is that time :)

In last commit I had to duplicate the findProjectJsonFile in two classes. They are in the KTerminalCommand and KRunCommand. Can you help me refactor this so that the code is not duplicated? Advice would be great but I'd really appreciate a PR.

@shirhatti can you review to ensure I didn't do anything stupid?

elliotec commented 10 years ago

The output after running "Run K Commands" since the most recent commit now displays this:

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 526, in run_
    return self.run()
  File "/Users/{user}/Library/Application Support/Sublime Text 3/Packages/Kulture/Kulture.py", line 202, in run
    file_name = self.findProjectJsonFile();
  File "/Users/{user}/Library/Application Support/Sublime Text 3/Packages/Kulture/Kulture.py", line 244, in findProjectJsonFile
    currentDir = os.path.dirname(currentFile);
  File "X/posixpath.py", line 151, in dirname
AttributeError: 'NoneType' object has no attribute 'rfind'
elliotec commented 10 years ago

I'm not too well practiced in Python either, but I may have the Ruby chops to help out. I can't find the code duplication you're referencing though. Also, I'm curious as to what project.json file is necessary and why it couldn't find it in the first place. Any insight?

sayedihashimi commented 10 years ago

@elliotec what platform are you on? Does it happen for every file you are in? Any particular repro steps?

The code is in https://github.com/ligershark/Kulture/blob/master/Kulture.py search for findProjectJsonFile

sayedihashimi commented 10 years ago

@elliotec OK that looks like the error when you are editing an unsaved file. We should have a better error message there.

sayedihashimi commented 10 years ago

@elliotec OK can you try it again I have just pushed a fix to master for this.

shirhatti commented 10 years ago

I personally think creating .sublime-project is right way to set this up. (see #13)

Doing a recursive directory search, especially in a UI thread seems like a bad idea. Additionally, we do not respect how a user has set up their directory structure and whether or not they want to follow symlinks.

Haven't got a chance to test out your code yet. Will try tomorrow on both Mac and Linux

sayedihashimi commented 10 years ago

@Shirhatti lets combine them. We should look for a .sublime-project and if its not there we search. The operations that are being performed should complete quickly. Lets keep an eye out for feedback.

elliotec commented 10 years ago

Most recent build output:

error: Kulture: Please save the file you are editing and try again
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 526, in run_
    return self.run()
  File "/Users/mike4life/Library/Application Support/Sublime Text 3/Packages/Kulture/Kulture.py", line 204, in run
    file_name = self.findProjectJsonFile()
  File "/Users/user/Library/Application Support/Sublime Text 3/Packages/Kulture/Kulture.py", line 249, in findProjectJsonFile
    raise NotFoundError(msg)
Kulture.Kulture.NotFoundError: Kulture: Please save the file you are editing and try again
Writing file /Users/mike4life/Desktop/[project]/Global.asax with encoding UTF-8 with BOM (atomic)
checking for project.json at: [location]
checking for project.json at: [/Users/user/Desktop/[dir]/project.json]
checking for project.json at: [/Users/user/Desktop/project.json]
checking for project.json at: [/Users/user/project.json]
checking for project.json at: [/Users/project.json]
checking for project.json at: [/project.json]
project.json found at: [/project.json]
Traceback (most recent call last):
  File "X/json/scanner.py", line 30, in _scan_once
IndexError: string index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "X/json/decoder.py", line 368, in raw_decode
  File "X/json/scanner.py", line 32, in _scan_once
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 526, in run_
    return self.run()
  File "/Users/user/Library/Application Support/Sublime Text 3/Packages/Kulture/Kulture.py", line 212, in run
    json_file = json.load(open(file_name))
  File "X/json/__init__.py", line 264, in load
  File "X/json/__init__.py", line 309, in loads
  File "X/json/decoder.py", line 352, in decode
  File "X/json/decoder.py", line 370, in raw_decode
ValueError: No JSON object could be decoded
sayedihashimi commented 10 years ago

@elliotec how can I reproduce this? Is it happening for all projects?

sayedihashimi commented 10 years ago

Has anybody else had a chance to try out the latest version in the master branch? Wondering how things are working for everyone.

sayedihashimi commented 10 years ago

I have made one further change in this area. Now before checking in the directory of the file being edited if there is a Sublime Project open the directory of that file is checked first. The changes are in commit 0a09e6e54a42992cd0e19da56f7e58257bd855a3. I created a wiki page to describe how it works https://github.com/ligershark/Kulture/wiki/How-does-Kulture-look-locate-project.json. Please check it out and if possible try it out.

Do we need any updates here?

elliotec commented 10 years ago

Still unable to use this. When selecting 'Run K Commands' it just prompts: "Kulture: Please save the file you are editing and try again" no matter what file, project, saved or not saved. I'm just following the instructions on the README.

Output is:

Could not import subprocess32 module, falling back to subprocess module
error: Kulture: Please save the file you are editing and try again
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 526, in run_
    return self.run()
  File "/Users/{user}/Library/Application Support/Sublime Text 3/Packages/Kulture/Kulture.py", line 225, in run
    file_name = self.findProjectJsonFile()
  File "/Users/{user}/Library/Application Support/Sublime Text 3/Packages/Kulture/Kulture.py", line 275, in findProjectJsonFile
    raise NotFoundError(msg)
sayedihashimi commented 10 years ago

@elliotec any idea how I can reproduce this? Is it happening on all your machines or just one?

I've never seen the message Could not import subprocess32 module, falling back to subprocess module not sure what could be causing that.

Has anyone else had a chance to try out the changes?

sayedihashimi commented 10 years ago

I haven't heard much feedback besides @elliotec reports. Things are working good for me on both mac and windows so I'm going to go ahead and merge this to Release later tonight so that the plugin gets updated.

sayedihashimi commented 10 years ago

OK I just released it in package control as version 2014.09.11.06.27.17.

sayedihashimi commented 9 years ago

Kulture is moving to a new home at https://github.com/OmniSharp/Kulture.

If this is still a problem please open a new issue at https://github.com/OmniSharp/Kulture/issues. Closing this now.

subodhjena commented 9 years ago

I still see the issue with the master branch code. Help much appreciated.

afortaleza commented 9 years ago

I am having the same issue. I am following "Create a Web API in MVC 6" tutorial from asp.net/vnext and the code has project.json into the src/ subfolder and "Run K Commands" does nothing and displays the same error notified in the thread.