|
7 | 7 |
|
8 | 8 | from .is_tex_file import is_tex_file
|
9 | 9 | from .logging import logger
|
| 10 | +from .sublime_utils import get_project_data |
10 | 11 | from .sublime_utils import get_project_file_name
|
11 | 12 |
|
12 | 13 |
|
@@ -110,48 +111,29 @@ def parse_tex_directives(view_or_path, multi_values=[], key_maps={}, only_for=[]
|
110 | 111 | lines.close()
|
111 | 112 |
|
112 | 113 |
|
113 |
| -# Contributed by Sam Finn |
114 | 114 | def get_tex_root(view):
|
115 | 115 | if not view:
|
116 | 116 | return None
|
117 | 117 |
|
118 | 118 | view_file = view.file_name()
|
119 | 119 |
|
120 |
| - root = None |
121 |
| - directives = parse_tex_directives(view, only_for=["root"]) |
122 |
| - try: |
123 |
| - root = directives["root"] |
124 |
| - except KeyError: |
125 |
| - pass |
126 |
| - else: |
127 |
| - if not is_tex_file(root): |
128 |
| - root = None |
129 |
| - elif not os.path.isabs(root) and view_file is not None: |
130 |
| - file_path, _ = os.path.split(view_file) |
131 |
| - root = os.path.normpath(os.path.join(file_path, root)) |
132 |
| - |
133 |
| - if root is None: |
134 |
| - root = get_tex_root_from_settings(view) |
135 |
| - |
136 |
| - if root is not None: |
137 |
| - return root |
138 |
| - return view_file |
139 |
| - |
140 |
| - |
141 |
| -def get_tex_root_from_settings(view): |
142 |
| - root = view.settings().get("latextools.tex_root", None) |
143 |
| - |
144 |
| - if root is not None: |
| 120 | + # from directive |
| 121 | + root = parse_tex_directives(view, only_for=["root"]).get("root") |
| 122 | + if root and is_tex_file(root): |
| 123 | + root = os.path.normpath(root) |
145 | 124 | if os.path.isabs(root):
|
146 |
| - if os.path.isfile(root): |
147 |
| - return root |
148 |
| - else: |
149 |
| - proj_file = get_project_file_name(view) |
150 |
| - |
151 |
| - if proj_file: |
152 |
| - project_dir = os.path.dirname(proj_file) |
153 |
| - root_path = os.path.normpath(os.path.join(project_dir, root)) |
154 |
| - if os.path.isfile(root_path): |
155 |
| - return root_path |
| 125 | + return root |
| 126 | + if view_file: |
| 127 | + return os.path.join(os.path.dirname(view_file), root) |
| 128 | + |
| 129 | + # from project-specific settings |
| 130 | + root = get_project_data(view).get("settings", {}).get("latextools.tex_root") |
| 131 | + if root and is_tex_file(root): |
| 132 | + root = os.path.normpath(root) |
| 133 | + if os.path.isabs(root): |
| 134 | + return root |
| 135 | + proj_file = get_project_file_name(view) |
| 136 | + if proj_file: |
| 137 | + return os.path.join(os.path.dirname(proj_file), root) |
156 | 138 |
|
157 |
| - return root |
| 139 | + return view_file |
0 commit comments