-
Notifications
You must be signed in to change notification settings - Fork 133
Use PathResolverSnapshot to find modules. #361
Use PathResolverSnapshot to find modules. #361
Conversation
src/Analysis/Engine/Impl/DependencyResolution/AvailablePackageImports.cs
Outdated
Show resolved
Hide resolved
src/Analysis/Engine/Impl/DependencyResolution/IAvailableImports.cs
Outdated
Show resolved
Hide resolved
src/Analysis/Engine/Impl/DependencyResolution/PathResolverSnapshot.Node.cs
Outdated
Show resolved
Hide resolved
var rootNodes = searchPaths.Where(Path.IsPathRooted).Select(Node.CreateRoot).Prepend(_roots[0]).ToArray(); | ||
return new PathResolverSnapshot(_pythonLanguageVersion, rootNodes, Version + 1); | ||
public PathResolverSnapshot SetUserSearchPaths(in IEnumerable<string> searchPaths) { | ||
var userSearchPaths = searchPaths.ToArray(); |
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.
User search paths can contain anything, like .
for example. VSC passed .
as one of the paths normally. Also, since we pass them down verbatim from user settings, I'd try/catch IOException since they can contain random characters and may be malformed.
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.
PathResolver never accesses file system, so there can't be any IOExceptions. Search paths are preserved in their form cause when _rootDirectory
is changed, we can try to convert relative path to absolute.
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 think Path.Combine(rootDirectory, p)
etc also throw when path parts are invalid, but that is ArgumentException
src/Analysis/Engine/Impl/DependencyResolution/PathResolverSnapshot.cs
Outdated
Show resolved
Hide resolved
src/Analysis/Engine/Impl/DependencyResolution/PathResolverSnapshot.cs
Outdated
Show resolved
Hide resolved
BTW, how does it work with |
@@ -382,6 +408,46 @@ static class PathUtils { | |||
return null; | |||
} | |||
|
|||
public static bool IsNormalizedPath(string path) { |
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 wonder if we can just PathUtil.NormalizePath(path) == path
?
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.
PathUtil.NormalizePath(path)
produces enormous amount of garbage. During initial load, some of that garbage even ends up in Gen2. So the goal was the opposite - don't create new path if the original one is normalized already.
Unfortunately,
So the only thing I can share is |
- Fixed namespace package resolution in completions (microsoft#12) - Fixed support for sys.modules (microsoft#363) - Added several tests (microsoft#365) - Fixed support for implicit relative module names (microsoft#366) - Added support for multiple matching rules in PathResolver (microsoft#367) Not yet implemented: - Fix imports of binary modules (microsoft#362) - Fix stubs handling - AstAnalysisWalker - More tests - Code cleanup
@@ -14,132 +14,344 @@ | |||
// See the Apache Version 2.0 License for specific language governing | |||
// permissions and limitations under the License. | |||
|
|||
using Microsoft.PythonTools.Analysis.Infrastructure; | |||
using Microsoft.PythonTools.Parsing; |
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.
Sorting
This needs tons of tests :-) |
I assume we merge it post Nov release? |
- Use PathResolverSnapshot in AstAnalysisWalker - More cleanup Bug to fix: PathResolverSnapshot.AddModulePath should add path to all roots where it matches, not just the first one.
… is created - Added support for native module file names with versions
Ok, I've removed the WIP prefix. There are some known bugs, but they can be fixed separately. |
# Conflicts: # src/Analysis/Engine/Impl/PythonAnalyzer.cs
…-server into NamespacePackages # Conflicts: # src/Analysis/Engine/Impl/Interpreter/Ast/AstBuiltinsPythonModule.cs
Given that this dependency resolver is independent from the analyzer and really only makes use of the AST, would it make more sense to move this into one of the new assemblies Mikhail is planning on creating in a future PR? The only |
@jakebailey - I will move the resolver to the proper assembly with my PR so new code can access it. Currently there is no separate assembly yet. |
Use PathResolverSnapshot to find modules.
No description provided.