-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Expose code inspection providers for the extensions. #5125
Conversation
@peterflynn can you review? i choose rather not to modify the original |
@peterflynn could we do this for sprint 31 please? :) |
var language = LanguageManager.getLanguageForPath(fileEntry.fullPath), | ||
languageId = language && language.getId(), | ||
provider = language && _providers[languageId]; | ||
return provider; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This duplicates code from run(), so I think you should modify run() to use this. I don't think it will be too disruptive to hoist out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, but you used language and languageId later, so you mean like return all three variables in object ?
What would you think of changing the API to something like: One thing I have in mind is the possibility of providers becoming async (#5137). An |
@zaggino Done reviewing. Just those two thoughts. |
@peterflynn Take a look please what do you think. Haven't modified any of the original code yet but this |
.done(function (fileText) { | ||
var perfTimerInspector = PerfUtils.markStart("CodeInspection '" + languageId + "':\t" + fileEntry.fullPath), | ||
scanPromise = $.when(provider.scanFile(fileText, fileEntry.fullPath)); | ||
Async.withTimeout(scanPromise, SCAN_TIMEOUT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to wrap this in a timeout -- we generally don't try to protect against bad/slow async extension code anywhere else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll remove it then. Will finish this tomorrow, almost 3am already in Syd :)
@zaggino This is looking like a good direction, yeah. |
Done, with a bit of optimization. Original code was multiplying event handlers on the results table with every render. That should be solved now. Please review @peterflynn |
@zaggino I haven't been able to give the latest changes a close look yet -- hopefully tomorrow. But from my quick glance, I'm a little concerned about possible race conditions in run(), e.g. if you switch files before the provider has returned results. Since we're getting close to the end of the sprint and thus a bit more risk-averse, I wonder if the best thing for now would be to take out the support for async providers. That makes it easier to land the API you need before the sprint ends -- and we could introduce async providers next sprint without breaking API compatibility. What do you think? |
@peterflynn it's not very difficult to check if the checked document is still the current document when the async provider finishes it's work... but I can disable it in this one to be safe and put up another PR with async |
and right now - unless someone installs an extension with async provider, it won't be used anyway... |
@zaggino There are other cases too, though -- you might modify & save the file a second time while the first linting is still running, or toggle the panel visibility, or disable linting... We probably shouldn't offer API support until we're sure it will work reliably. |
ok @peterflynn , i'll remove the async parts to keep this simple for now |
Done, |
@peterflynn Can we merge now? I see Sprint 32 in the master. |
|
||
/** | ||
* Gets a provider for given fileEntry, if one is available | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs type annotations for argument & return values. Ditto for inspectFile() below -- every public API (at minimum) should have these docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, nit: the double spacing after the *
is inconsistent with how the rest of the file is formatted.
@zaggino Looking good -- just a few minor comments. |
Actually two other thoughts:
|
Fixed the comments. About the FileEntry vs FullPath thing, currently in my extension I have this piece of code to call the method, so fullPath would be easier in my situation but might not be better for others. |
Oops, actually one more thing, now that I've been running on this branch: the built-in JSLint provider returns null anytime there are no errors, so the console winds up littered with warnings. I wonder if we should actually get rid of the warning and just continue to allow null as a return value? Now that run() uses getProvider() as a helper, we don't really need non-null results to help disambiguate no-provider vs. no-errors... |
Ok, I've removed the warning. |
Great! I'll wait until tomorrow morning to see if @gruehle has any thoughts on the FileEntry vs. fullPath question, but personally I'm leaning toward the path. It's easy to call that form whether you have a FileEntry wrapper or not, which is nice. (And then we should rename the API accordingly). Also had one other suggestion, if we're going to make one more commit anyway: I think the docs for |
Ok, will fix that comments ... also I can squash these commits into one before merging, so the history of the main repo is not polluted unnecessarily with too many commits. |
Yeah, I prefer using a pathname for I had another thought: why not store the code inspection provider on the language object? This way you can just use |
Did the One more thought, currently there is only one possible file inspector for one language but in the future, there might be desired feature to support multiple code inspectors who check for different things. Like I can use jshint on my JavaScript files but I also want an extension that checks for patterns that are forbidden in a specific framework like dojo or yui. |
@zaggino Very good point. So, what's the use case for |
@gruehle We have other things that are language-specific too, like code hint providers, Quick Open providers, etc. and we don't hang those directly off the Language object. We could stuff them all into the Language, but it starts to feel a little iicky to me in a separation-of-concerns sense... feels nicer to have each of those subsystems own its own data. |
I've removed Currently if there's no default provider for the given file type, |
@peterflynn Good point about the other language-specific features. I agree that it doesn't make sense to clutter up Language like that. Making |
@zaggino Looks good to go! Did you still want to make a squashed version? |
First go at inspectFile method. Removed Async.withTimeout from inspectFile() Separated getProvider and inspectFile logic, added usage of DocumentManager.getOpenDocumentForPath to inspectFile Modified run() to use new methods. Moved $problemsPanelTable event handlers from run() to htmlReady() for optimization. Fix the case when getCurrentDocument returns null. Check if current document hasn't changed while inspectFile was running remove async handling of provider.scanFile Refactored according to comments. Made provider response nullable again, removed the warning. Refactored getProvider to getProviderForPath and updated docs. Remove getProvider from exports.
Yes, that'll be better. Squashed now. |
@peterflynn ready to go, but this will certainly create merge problems with #5235 |
Looks good -- thanks for being patient! #5235 is just starting review, so there's plenty of time to sort out the conflicts over there. I think this one is ready to land now. |
Expose API to run code inspection as a headless one-off on an arbitrary file
As mentioned in #4588 (comment)
API that fetches the active linting provider for a given file entry.