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

Refactor JinjaTracer: Split into two classes, break up _slice_template() function #2870

Merged
merged 18 commits into from Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements_dev.txt
Expand Up @@ -22,6 +22,7 @@ types-chardet
types-appdirs
types-colorama
types-pyyaml
types-Jinja2
Copy link
Member Author

Choose a reason for hiding this comment

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

Unrelated to the rest of the PR, but I noticed we were missing this

types-regex
# Requests is required for the util script
requests
Expand Down
5 changes: 3 additions & 2 deletions src/sqlfluff/core/templaters/jinja.py
Expand Up @@ -24,7 +24,7 @@
TemplatedFileSlice,
)
from sqlfluff.core.templaters.python import PythonTemplater
from sqlfluff.core.templaters.slicers.tracer import JinjaTracer
from sqlfluff.core.templaters.slicers.tracer import JinjaAnalyzer


# Instantiate the templater logger
Expand Down Expand Up @@ -413,6 +413,7 @@ def slice_file(
templater_logger.info("Slicing File Template")
templater_logger.debug(" Raw String: %r", raw_str)
templater_logger.debug(" Templated String: %r", templated_str)
tracer = JinjaTracer(raw_str, self._get_jinja_env(), make_template)
analyzer = JinjaAnalyzer(raw_str, self._get_jinja_env())
tracer = analyzer.analyze(make_template)
trace = tracer.trace()
return trace.raw_sliced, trace.sliced_file, trace.templated_str