Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Fixed LSP Linting Synchronization Issues #14685

Merged
merged 3 commits into from
Apr 5, 2019
Merged

Fixed LSP Linting Synchronization Issues #14685

merged 3 commits into from
Apr 5, 2019

Conversation

niteskum
Copy link
Collaborator

@niteskum niteskum commented Apr 3, 2019

@shubhsnov please review.
@narayani28

@@ -335,16 +335,21 @@ define(function (require, exports, module) {

function LintingProvider() {
this._results = new Map();
this._defferedLintingPromise = new Map();
Copy link
Collaborator

@shubhsnov shubhsnov Apr 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the member variables have issues:

  • deffered => deferred (typo)
  • change defferedLintingPromise to something which seems more intuitive for a map (suggestion: use 'promises' or 'promiseMap' in the name)
  • V => v (lowercase, only Modules and Classes are capitalized by convention)
  • lintingName => could be changed to 'providerName' or 'linterName'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

this._defferedLintingPromise.get(filePath).resolve(this._results.get(filePath));
this._defferedLintingPromise.delete(filePath);
}
if (this._ValidateOnType) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few issues:

  • Check if filePath === currentActiveDocumentPath? No need to run inspection for files which are not active.
  • How is onSave being handled here?
  • Why do we need a promiseMap here at all? The request is being run once we have already gotten the result.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shubhsnov on File Save and File Open diagnostics would be run by CodeInspection Manager itself.
in case of file open Diagnostics result won't be available immediately in that case result will be return using promise

Copy link
Collaborator

@shubhsnov shubhsnov Apr 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. One more question, if the promise is only for the file open scenario then why do we require a Map? We can just keep a promise for the current doc since we are already not running the code inspection request for any inactive docs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileOpen scenario is the the sceanrio which I could think where result might not be available. there could be other scenarios as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, we only show the linting for the current file. Only having currentActiveDocPromise should suffice. No point in caching since the cached result will never be used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please add a check in the getInspectionResultsAsync for filePath === currentActiveDocumentPath as well.

already fixed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please add a check in the getInspectionResultsAsync for filePath === currentActiveDocumentPath as well.

already fixed

I specifically meant for getInspectionResultsAsync not setInspectionResultsAsync. It would act as a guard and optimization. Suppose a file has hundred of errors, but we switched to any other file before actually getting the results. Why would we want those hundred of results to pass through another function callback and then get discarded, since the active file changed. Doesn't seem proper to me. If we have a check in set, we should have a check in get.

Copy link
Collaborator Author

@niteskum niteskum Apr 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shubhsnov Not Sure if you are looking at complete code workflow from CodeInspection side. It looks perfectly ok to me. the guard you are mentioning is already in place in codeInspection. CodeInspection always call getInspectionResultsAsync for current File only.
and this function can't return null, It has to return promise.

If still not clear we can discuss this.

Copy link
Collaborator

@shubhsnov shubhsnov Apr 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an optimization. Okay let me explain it to you more clearly here:
You open File A (Some large file which let's assume will take some time for the diagnostics response)
getInspectionResultsAsync will get called
Just as the function was called you switched the document
Now you are inside the getInspectionResultsAsync for File A but the active Document is File B

Now according to me, instead of creating a promise and waiting for the promise to resolve, we can instead do $.Deferred().resolve(null) because it won't matter, as CodeInspection will drop the promise as it is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not taking this change as I am not convinced that it is an optimization. we are just double checking if the file is current file.

@shubhsnov shubhsnov changed the title Fixed LSP Linting Synchrnization Issues Fixed LSP Linting Synchronization Issues Apr 3, 2019
@@ -107,7 +107,7 @@ define(function (require, exports, module) {
CodeHintManager.registerHintProvider(chProvider, ["php"], 0);
ParameterHintManager.registerHintProvider(phProvider, ["php"], 0);
CodeInspection.register(["php"], {
name: Strings.PHP_DIAGNOSTICS,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have something here to differentiate from any other provider which might also provide "php" related linting.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed we are not having any name for default PHP Lint Provider

@shubhsnov
Copy link
Collaborator

LGTM 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants