Kapiainen / SublimePapyrus

A Sublime Text 2 and 3 package for the Papyrus scripting language.
MIT License
47 stars 8 forks source link

Problem with code completion #31

Closed jimkaiseriv closed 7 years ago

jimkaiseriv commented 7 years ago

I'm having an intermittent problem with code completion in Sublime 2. When I first fire up Sublime, everything works as expected after I save the script once (The message in the status bar says the Linter needs to be run once. After I save the script, even without making changes, autocomplete begins to work). However, I find that it may stop working if I make changes to my code that temporarily cause a number of lines to be invalid. As an example, with code like this:

1 Event myevent() 2 dosomething() 3 EndEvent 4 5 Function dosomething() 6 7 EndFunction

I changed Event myevent() to Function mynewfunction(), and neglected to change the EndEvent keyword until some point later, probably following a save. I noticed that the status bar had a message that dosomething() on line 2 wasn't valid in this scope, and that this message persisted even after I made the correction and even if I commented out line 2. At this point the code would compile just fine, but the code completion feature would not work EXCEPT for basic keywords, as well as functions and variables I had defined in that specific file. That is to say, it would not complete for any inherited functions or properties, or for any of the functions defined in Skyrim's source scripts. The only solution I've found so far is to restart Sublime, after which everything works again as expected.

This is just one example, but I've experienced the code completion failing several times recently in various similar circumstances. I should mention that I'm working with multiple files that extend each other, and the changes I'm making would effect more than one script at a time, but that even when any errors are corrected the code completion continues to fail for all of the open scripts until I restart Sublime. If it would help, I can attach several files I'm working on with specific instruction on how I can reliably reproduce the problem.

Kapiainen commented 7 years ago

I would greatly appreciate having the source code and step by step instructions. A quick replication attempt based on what you've already posted did not yield any issues on my end. Could you also have a look at the Sublime Text console (View > Show Console in the toolbar) on your end for errors when this issue arises?

jimkaiseriv commented 7 years ago

Alright, I've written a fairly simple set of files, and I can consistently cause the code completion to break on them. I'm attaching both files here. The one does extend the other, and I am updating a function definition on both when the problem arises. I attempt to build the files while there is an error, fix the error, attempt to build again, and then notice that code completion no longer works. I also notice that the status bar is stuck showing an error message even though I have fixed it and successfully built the scripts. I have attached both files here, and included in the files the precise steps I follow to replicate the issue. I also looked at the console and found the following error:

Traceback (most recent call last): File ".\sublime_plugin.py", line 190, in on_post_save File ".\sublime_plugin.py", line 154, in run_timed_function File ".\sublime_plugin.py", line 189, in File ".\Plugin.py", line 174, in on_post_save File ".\Plugin.py", line 478, in Linter AttributeError: 'NoneType' object has no attribute 'show_quick_panel'

Also, as I posted the error message above I was reminded that I have the plugin setting linter_panel_error_messages set to true. I've checked and this is the only plugin setting I have changed from the default currently.

UPDATE: In fact, as I typed up this post I tried changing the setting linter_panel_error_messages to false and I could no longer reproduce the issue, even though I could reliably do so before. I tend to recall that I still experienced the problem before turning that setting on initially, although by now I am not 100% certain and could be mistaken on that point.

CodeCompletionTest.zip

Kapiainen commented 7 years ago

Thanks. I was now able to replicate the results and as you noted the linter_panel_error_messages setting has to be true for the problem to show up. A function in Sublime Text 2's API returns None in this specific situation (and I'm still trying to figure out exactly why) whereas Sublime Text 3 fails safely ("Quick panel unavailable" is printed in the console and everything continues working just fine). I'll continue to look into this issue. The worst case scenario will involve just adding an if-condition to check what the function in question returns prior to trying to call another function on that return value. In the best case scenario I can figure out exactly what is causing None to be returned.

Kapiainen commented 7 years ago

I think I've figured out the cause of the problem and it seems like it might be a bug in or a characteristic of ST2's API. Only the active view can return a reference to the window containing said view in ST2, but in this case two views are being processed and only one of them can be the active view. ST3 does not have this issue because any view can return a reference to the window containing it. The function for showing the quick panel also fails safely in ST3 when an instance of that panel is already being shown.

Looks like I won't be able to fix the actual cause of the problem in ST2, but I can at least avoid the problem in SublimePapyrus by adding an extra if-statement.

Kapiainen commented 7 years ago

Version 2.6.4 should fix the issue.

jimkaiseriv commented 7 years ago

Great news! Thanks!