Closed case56 closed 8 years ago
Thanks for the report! I will try and look into this during the weekend.
We use a regular expression, '^\s*(//|#)'
in order to grab only lines that don't start with a comment, and then send those to Maya (for both MEL and Python). As you can see in that pattern, we don't try and account for MEL /* */
comment blocks, or even python triple quote blocks. I was doing this to reduce the amount of data being sent to Maya. But as you have seen, it will make the line counts not match what Maya reports when there are errors.
But I have a question... Is the line report from Maya really all that helpful in the context of sending a snippet of code from an arbitrary location in your file in SublimeText? i.e. if you select from text from lines 100-110 and send it to Maya and there is an error... is it really that helpful to see maya tell you the error was on line 5 of your code?
I could remove the logic that strips out comment lines to make it all get sent to Maya, as-is, but I would like to know a little bit more about how having a different line count in the error would improve the workflow?
Hi Justin,
Thanks for taking a look at this so soon. I'm not a qualified software engineer so I can't comment on correct or common practices for scripting and debugging (Would love to hear input from others!).
For me its fairly important to have correct warning line counts, I'm not the best typist, I make a lot of edits, then submit the code and address errors as they are returned.
The way I've been working (with mel) is to have a script file of no more than 500 lines containing all my code within procedure blocks. More often than not after edits I'll select All of the code, send it to Maya, then check any resulting warnings in the history pane and use the returned line counts to pinpoint and address any syntax/logic errors etc..
For small snippets I wouldn't select and send more than 10 lines at a time, so counting any warning line counts manually within the selection isn't difficult.
Is stripping out comments to reduce the amount of data sent to Maya of much benefit?
It would be nice to have the choice. Perhaps another config option to enable/disable comment stripping?
That is a fair explanation of the workflow. No need to be any more qualified. So it makes sense that you would expect the line numbers to be accurate when sending the whole files. We actually do send the whole file explicitly, as well, when you have nothing selected, in a more efficient way. That is related to part of the reason why I had been stripping comments...
bufferSize(bs) Commands and results are each subject to size limits. This option allows the user to specify the size of the buffer used to communicate with Maya. If unspecified the default buffer size is 4096 characters. Commands longer than bufferSize characters will cause the client connection to close. Results longer that bufferSize characters are replaced with an error message.
I had been trying to prevent this buffer from being reached, by reducing the amount of data sent on a request. When you have nothing selected, instead of sending the literal code from your file, we send a command to tell maya to execute your file directly. This means you could send arbitrarily large files, regardless of the buffer size of the commandPort.
I can make this an option that you can enable: "Strip single-line comments when sending to Maya = True". Then you can turn it off when you know you want more accurate line numbers and you know you aren't doing massive. Or maybe I could look into asking Maya what the buffer size of the commandPort is. Will keep investigating.
I've also noticed that the commandPort MEL interpreter seems to strip away blank lines in a selection. Do you notice that as well? So if I sent the following:
int $myint;
// below returns: Warning: Line 2.31 : Converting string "I'm" to an int value of 0.
$myint = "I'm not an integer!";
... I still get line counts that act if it is only considering 3 lines. So if that is the case, I don't know how the line counts would be accurate, even if I stopped stripping comments.
Do you want to give this branch, 23_comment_stripping, a try before I merge it?
You can now set the following in your MayaSublime user settings: "strip_sending_comments": false
Also, even without this fix, if you send the whole saved file by not selecting anything before hitting your "ctrl+enter" keys, it would always send the whole file without skipping lines.
Thanks mate!
Wasn't aware not selecting anything would parse the whole file, I was always selecting all code with "ctrl+a" then "ctrl+enter" to send the selection to maya... "ctrl+enter" without a selection does indeed return the correct line count without skipping comments or blank lines for me, and at a guess looks to be the same as sourcing the script file from maya, awesome!
Knowing this, having correct warning line counts returned from sent snippets (selections) becomes less of an issue for me, however I can see how this could still confuse some users without clarification. And having an option to prevent comment stripping is certainly a welcome addition for me :)
testing branch #23 feedback:
"strip_sending_comments"
switch works well.
Have also noticed blank lines are removed from sent snippets but only blank lines from the very beginning of the selection. eg.
In the returned warning, 3 lines are trimmed from the count, the 1st 2 blank lines and the comment line(8), error on line 9 becomes 6. Which means blank lines 4-6 are included in the count.
Right. But I don't believe the plugin is doing the stripping of those beginning lines. I confirm that we really are sending the snippet to Maya with the leading newlines. They get dropped by Maya, so I guess that is unavoidable.
I will merge this optional setting to turn of the comment stripping that the plugin is actually doing. And like you said, using the approach where Maya actually sources the file is a complete working solution already
On Sun, 6 Mar 2016 10:03 PM case56 notifications@github.com wrote:
Thanks mate!
Wasn't aware not selecting anything would parse the whole file, I was always selecting all code with "ctrl+a" then "ctrl+enter" to send the selection to maya... "ctrl+enter" without a selection does indeed return the correct line count without skipping comments or blank lines for me, and at a guess looks to be the same as sourcing the script file from maya, awesome!
Knowing this, having correct warning line counts returned from sent snippets (selections) becomes less of an issue for me, however I can see how this could still confuse some users without clarification. And having an option to prevent comment stripping is certainly a welcome addition for me :)
testing branch #23 https://github.com/justinfx/MayaSublime/issues/23 feedback: Also have noticed blank lines are removed from sent snippets but only blank lines from the very beginning of the selection. eg.
1. 2.
- int $yourint; 4. 5. 6.
- int $myint;
// below returns: Warning: Line* 6.31* : Converting string "I'm" to an int value of 0.
1. 2. 3. 4. 5.
$myint = "I'm not an integer!";
1. 2. 3. 4. 5.
In the returned warning, 3 lines are trimmed from the count, the 1st 2 blank lines and the comment line(8), error on line 9 becomes 6. Which means blank lines 4-6 are included in the count.
— Reply to this email directly or view it on GitHub https://github.com/justinfx/MayaSublime/issues/23#issuecomment-192841597 .
Firstly thanks for this great package, could not have finished my final course project to the same level without it, love it!
One thing I've noticed when sending mel code snippets to maya and there are errors in the sent code including "//" style comments, the comment lines are subtracted from the total line count in any warning messages returned in maya's history pane. This may or may not be related to issue #21.
eg.
multi line comments return the correct warning line number:
As a work around we can just always use multi line comments, but I thought I'd bring this to your attention, as it made debugging my script kind of confusing before I realized the problem.