Skip to content

Commit

Permalink
Add typeshed path
Browse files Browse the repository at this point in the history
  • Loading branch information
Glyphack committed Nov 13, 2023
1 parent b32b529 commit 58515d1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "typeshed"]
path = typeshed
url = https://github.com/python/typeshed
12 changes: 10 additions & 2 deletions enderpy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -54,6 +55,12 @@ fn get_python_executable() -> Result<PathBuf> {
Ok(PathBuf::from(path))
}

fn get_typeshed_path() -> Result<PathBuf> {
// 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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion lsp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ impl Backend {
async fn check_file(&self, path: PathBuf) -> Vec<Diagnostic> {
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,
};

Expand Down
1 change: 1 addition & 0 deletions typeshed
Submodule typeshed added at 676446

0 comments on commit 58515d1

Please sign in to comment.