Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to determine global variable values based on source tree #341

Open
hendrikvanantwerpen opened this issue Nov 7, 2023 · 1 comment

Comments

@hendrikvanantwerpen
Copy link
Collaborator

JavaScript and TypeScript use PROJECT_NAME and FILE_PATH variables, which are supposed to be inferred from package.json or tsconfig.json locations. This inference process is currently implemented in another process, making testing this behavior cumbersome: one has to provide these variables explicitly in the tests, for each file.

Language configurations should be able to provide a custom procedure to determine the value for global variables for source files.

@hendrikvanantwerpen
Copy link
Collaborator Author

Idea: TreeAnalyzers

Similar to FileAnalyzer we define a TreeAnalyzer trait which can be implemented for languages. A tree analyzer takes the source listing and produces a mapping from source files to global variables. These global variables are passed to the file analyzer.

A nice effect of this is that the source file list argument can be removed from the FileAnalyzer trait, at which point a StackGraphLanguage implements FileAnalyzer and everything becomes more uniform.

As part of this, we could/should provide a trie-like datastructure that allows us to set globals on directories as well as files, and returns all globals in effect for a source file. For example, set the PROJECT_NAME variable on the project root, and the FILE_PATH on the file, and when asked for the globals of a file in that directory, return both PROJECT_NAME and FILE_PATH values.

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

No branches or pull requests

1 participant