[+] fix relative_to error, vim config

This commit is contained in:
Siarhei Siniak 2025-10-11 16:34:14 +03:00
parent 81f3fc494a
commit 31cd7c35c9

@ -187,10 +187,18 @@ class EditorConfigModeline:
@classmethod
def find_entry(
cls,
config: dict[str, str],
file_path: pathlib.Path
file_path: pathlib.Path,
config: Optional[dict[str, str]] = None,
) -> Optional[str]:
rel_path = file_path.relative_to(pathlib.Path.cwd())
if config is None:
return None
project_root = pathlib.Path.cwd()
if file_path.is_relative_to(project_root):
rel_path = file_path.relative_to(pathlib.Path.cwd())
else:
rel_path = file_path
for pattern, modeline in config.items():
if fnmatch.fnmatch(str(rel_path), pattern):
@ -206,7 +214,7 @@ class EditorConfigModeline:
buf_name = vim.current.buffer.name
file_path = pathlib.Path(buf_name).resolve()
entry = self.find_entry(config, file_path)
entry = self.find_entry(file_path, config=config)
logger.info(dict(modeline=entry))