Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

Report unresolved imports #593

Merged
merged 292 commits into from
Feb 13, 2019
Merged

Report unresolved imports #593

merged 292 commits into from
Feb 13, 2019

Conversation

MikhailArkhipov
Copy link

@MikhailArkhipov MikhailArkhipov commented Feb 10, 2019

Closes #583
Closes #512

I guess I will need to re-fork my master since all commits from earlier work still drag behind.

@jakebailey
Copy link
Member

I don't know the exact line in the PR to comment on but for as imports, but I think that the original name is the more useful one to be reporting. For example, matplotlib/matplotlib.pyplot is the thing that's missing here, but the message reports plt:

image

@jakebailey
Copy link
Member

For example, in the old LS:

image

@MikhailArkhipov
Copy link
Author

Yep, changing

analysis.Diagnostics.Should().HaveCount(1);
var d = analysis.Diagnostics.First();
d.ErrorCode.Should().Be(ErrorCodes.UnresolvedImport);
d.SourceSpan.Should().Be(1, 8, 1, 19);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use Range instead of SourceSpan?

Copy link
Author

Choose a reason for hiding this comment

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

Range is not in analysis, it is in LSP. Can theoretically move it down.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought Diagnostics is part of LSP as well. We also have IndexSpan.

Copy link
Author

Choose a reason for hiding this comment

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

Diagnostics yes. DiagnosticsEntry, no. Switching away from SourceSpan would require changing tens of tests. Analysis is using LocationInfo which produces SourceSpan.

@@ -460,6 +460,11 @@ public override void Add(string message, SourceSpan span, int errorCode, Severit
OnAnalysisComplete();
ContentState = State.Analyzed;

// Do not report issues with libraries or stubs
Copy link
Contributor

Choose a reason for hiding this comment

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

What if user has opened library file explicitly?

Copy link
Member

Choose a reason for hiding this comment

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

Also see: #584 (comment)

Copy link
Author

Choose a reason for hiding this comment

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

We don’t report issues in libraries, this is not something actionable to the user. Something like resharper does not produce issues in disassembled code...


public DiagnosticsSeverityMap(string[] errors, string[] warnings, string[] information, string[] disabled) {
_map.Clear();
// disabled > error > warning > information
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it compatible with VSC?

Copy link
Author

Choose a reason for hiding this comment

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

Yes. Same code as before

set {
lock (_lock) {
_severityMap = value;
PublishDiagnostics();
Copy link
Contributor

Choose a reason for hiding this comment

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

One more place under lock.

Copy link
Author

@MikhailArkhipov MikhailArkhipov Feb 13, 2019

Choose a reason for hiding this comment

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

As a matter of fact, I made PublishDiagnostics inside locks intentionally. The problem here if publishing goes off the lock, then we can go out of sync between _changed and the state of the collection. For example,

        public void Remove(Uri documentUri) {
            lock (_lock) {
                // Before removing the document, make sure we clear its diagnostics.
                _diagnostics[documentUri] = new List<DiagnosticsEntry>();
                PublishDiagnostics();
                _diagnostics.Remove(documentUri);
            }
        }

PublishDiagnostics must be called between _diagnostics[documentUri] = new List<DiagnosticsEntry>() which makes collection of the error empty and VSC clears the task list and _diagnostics.Remove(documentUri) which removes the document. Calling PublishDiagnostics after removal will lead to stale errors in the error list.

In the code above if we do _diagnostics[documentUri] = new List<DiagnosticsEntry>() and persist to array, then call PublishDiagnostics off the lock, and then do _diagnostics.Remove(documentUri); under lock again, the document can technically get reopened while we are not under lock and we will remove document incorrectly.

It's probably small price to pay since we don't wait and basically just post the diagnostics under the lock.

};
_clientApp.NotifyWithParameterObjectAsync("textDocument/publishDiagnostics", parameters).DoNotWait();
}
diagnostics = Diagnostics.ToArray();
Copy link
Contributor

Choose a reason for hiding this comment

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

We aren't calling _diagnostics.Clear(); anywhere. Is that correct?

Copy link
Author

Choose a reason for hiding this comment

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

ClearAllDiagnostics, on Dispose. Otherwise it stays.

@MikhailArkhipov MikhailArkhipov merged commit 037d248 into microsoft:master Feb 13, 2019
jakebailey pushed a commit to jakebailey/python-language-server that referenced this pull request Nov 1, 2019
* Part 7

* Buildable

* PR feedback

* Merge conflict

* Fix microsoft#446

* Fix microsoft#446

* Part 8

* Part 9

* Buildable

* Part 10

* Part 11

* Part 12

* Buildable

* Part 14

* First passing test

* Simplify configuration

* Style

* Fix test and move code to folders

* Builtins import

* Fix microsoft#470

* Fluents

* Add search path

* Import analysis, part I

* Simplify builtins handling

* Remove IMember

* Handle import specific

* More tests

* Add typeshed

* Renames

* Make sure lazy modules are loaded

* Renames

* Move/rename

* Rework importing

* Derivation rework

* Part 2

* Part 3

* Buildable

* Module members

* Async walk

* Imports test pass

* Remove lazy types

* Fix from import

* Stubs

* Double overloads

* Fix datetime test

* Couple more tests + fluents

* Few more tests

* Additionl test + union type

* Built-in scrape tests

* Full stdlib scrape test

* Complete async AST walker

* Conditional defines test + variable loc cleanup

* More stub tests
Fix stub loading for packages (port from DDG)
Split walker into multiple files

* Add some (broken mostly) tests from DDG

* Move document tests

* Function arg eval, part I

* Instance/factory

* Builds

* Test fixes

* Fix static and instance call eval

* More tests

* More ported tests

* Specialize builtin functions

* Make walkers common and handle nested functions

* Moar tests

* Parser fixes + more tests

* Handle negative numbers

* Fix null ref

* Basic list support

* Few more list tests

* Basic iterators

* Support __iter__

* Iterators

* Fix couple of tests

* Add decorator test

* Generics, part I

* Generics, part 2

* Generics, part 3

* Basic TypeVar test

* Typings, part 4

* Fix test

* Generics, part 6

* Generics, part 7

* More tests (failing)

* Forward ref fixes

* Reorg

* Improve symbol resolution + test fixes

* Test fixes

* Dictionary, part I

* Part 11

* Fix test

* Tests

* Tests

* More dict work

* List ctor

* Skip some tests for now

* Fix iterators

* Tuple slicing

* Polish type comparo in return types

* Add Mapping and tests

* Add Iterable

* Fix typo

* Add Iterator[T] + test

* Simplify typing types

* Class reduction

* Fix tests

* Test fix

* Handle 'with' statement

* Handle try-except

* Class method inheritance + NewType

* Container types

* Containers test

* Tests

* Handle generic type alias

* Named tuple

* Global/non-local

* Handle tuples in for
Handle custom iterators

* Basic generator

* Any/AnyStr

* Test fixes

* Type/Optional/etc handling

* Proper doc population

* Tests + range

* Argument match

* Basic argset and diagnostics

* Argset tests

* Exclude WIP

* Exclude WIP

* Arg eval

* Arg match, part 2

* Tests and generic arg comparisons

* Function eval with arguments

* Baselines

* Fix test

* Undo AST formatting change and update baseline

* LS cleanup 1

* Fix list ctor argument unpacking

* Cleanup 2

* Builds

* Partial completions

* Partial

* Partial

* Simple test

* Tests

* Basic startup

* Clean up a bit

* Remove debug code

* Port formatter tests

* Fix tokenizer crash

* Async fixes

* Hover

* Basic hover

* Adjust expression options

* Basic signature help

* Fix class/instance

* Update test

* Fix builtin creation exception

* Fix tests

* Actually provide declared module

* Completion test (partial)

* Undo

* Fix null await
Fix override completions + test

* Exports filtering
Prevent augmenting imported types

* Filter variables & exports

* Ported tests

* Test fixes

* More ported tests

* Fix exception completions

* Import completions

* Scope completions

* With completions

* Test fixes

* WIP

* Test fix

* Better arg match

* Temp disable WIP

* First cut

* Fix type leak

* WIP

* Remove ConfigureAwait and handle canceled and failed in the analysis notifications

* WIP

* Generic class base

* Generic forward reference resolution

* Suppress completion in strings + test

* Prevent recursion on generic resolution
Better match arguments

* Handle call expression in generics

* Relax condition as it happens in tensorflow

* Fix typeshed version search
Make writing cached modules async
Fix module doc fetching

* Hover tests

* Fix prom import hover

* Hover tests

* Synchronize test cache writing

* First cut

* Test

* Fixes

* Add tests for os.path
Null ref fix

* Fix cache check

* Improve resolution of builtins and typing in stubs

* Merge tests

* Add ntst for requests

* Handle typeshed better

* Fix custom stub handling

* Better sync

* Move files

* Fix parameter locations

* Hover improvement

* PEP hints

* One more test for PEP hints

* Better handle hover over import as

* Text based generic constraints

* Handle with better with generic stubs

* Undo debug

* Handle non-binary open()
Temporary fix 'with' handler since we haven't specialized IO/TextIO/BinaryIO yet.

* Output syntax errors

* Properly clear

* - Fix async issue with analysis completion
- Clean up diagnostics service interface
- Use real DS in tests

* Use proper scope when analyzing module

* Severity mapping and reporting

* Add publishing test
Add NSubstitute
Move all services to the same namespace.

* Unused var

* Test forced publish on close

* Fix typo

* Update test framework

* Import location

* Remove incorrect reference

* Diagnostic severity mapping test
Fix post-mortem earlier PR comment

* Minor fixes

* Move interface to the main class part

* Flicker reduction

* - Correct reported unresolved import name
- Add tests

* PR feedback
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.

Report unresolved imports Diagnostic list flickers annoyingly when opening a document
3 participants