diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..4f35b337 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "typeshed"] + path = typeshed + url = https://github.com/python/typeshed diff --git a/enderpy/src/main.rs b/enderpy/src/main.rs index 11d034c9..8d087d59 100644 --- a/enderpy/src/main.rs +++ b/enderpy/src/main.rs @@ -27,10 +27,11 @@ fn symbols(path: &PathBuf) -> Result<()> { let initial_source = BuildSource::from_path(path.to_path_buf(), false); let dir_of_path = path.parent().unwrap(); let python_executable = Some(get_python_executable()?); + let typeshed_path = Some(get_typeshed_path()?); let settings = Settings { debug: true, root: dir_of_path.to_path_buf(), - import_discovery: ImportDiscovery { python_executable }, + import_discovery: ImportDiscovery { python_executable, typeshed_path }, follow_imports: enderpy_python_type_checker::settings::FollowImports::All, }; @@ -54,6 +55,12 @@ fn get_python_executable() -> Result { Ok(PathBuf::from(path)) } +fn get_typeshed_path() -> Result { + // imagine the path is in the same directory as user ran this command + let path = std::env::current_dir().into_diagnostic()?; + Ok(path.join("typeshed")) +} + fn tokenize(file: &PathBuf) -> Result<()> { let source = fs::read_to_string(file).into_diagnostic()?; let mut lexer = Lexer::new(&source); @@ -83,10 +90,11 @@ fn check(path: &PathBuf) -> Result<()> { let initial_source = BuildSource::from_path(path.to_path_buf(), false); let root = find_project_root(path); let python_executable = Some(get_python_executable()?); + let typeshed_path = Some(get_typeshed_path()?); let settings = Settings { debug: true, root: PathBuf::from(root), - import_discovery: ImportDiscovery { python_executable }, + import_discovery: ImportDiscovery { python_executable, typeshed_path }, follow_imports: enderpy_python_type_checker::settings::FollowImports::Skip, }; let mut build_manager = BuildManager::new(vec![initial_source], settings); diff --git a/lsp/src/main.rs b/lsp/src/main.rs index b93983ad..179a7298 100644 --- a/lsp/src/main.rs +++ b/lsp/src/main.rs @@ -20,10 +20,12 @@ impl Backend { async fn check_file(&self, path: PathBuf) -> Vec { let root = PathBuf::from(find_project_root(path.as_path())); let python_executable = None; + let path = std::env::current_dir().unwrap(); + let typeshed_path = Some(path.join("typeshed")); let settings = Settings { debug: false, root, - import_discovery: ImportDiscovery { python_executable }, + import_discovery: ImportDiscovery { typeshed_path, python_executable }, follow_imports: enderpy_python_type_checker::settings::FollowImports::Skip, }; diff --git a/typeshed b/typeshed new file mode 160000 index 00000000..67644656 --- /dev/null +++ b/typeshed @@ -0,0 +1 @@ +Subproject commit 676446569dddaca76500178599b05045ae2c3e6a