[+] fix relative_to error, vim config
This commit is contained in:
parent
81f3fc494a
commit
31cd7c35c9
@ -187,10 +187,18 @@ class EditorConfigModeline:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def find_entry(
|
def find_entry(
|
||||||
cls,
|
cls,
|
||||||
config: dict[str, str],
|
file_path: pathlib.Path,
|
||||||
file_path: pathlib.Path
|
config: Optional[dict[str, str]] = None,
|
||||||
) -> Optional[str]:
|
) -> 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():
|
for pattern, modeline in config.items():
|
||||||
if fnmatch.fnmatch(str(rel_path), pattern):
|
if fnmatch.fnmatch(str(rel_path), pattern):
|
||||||
@ -206,7 +214,7 @@ class EditorConfigModeline:
|
|||||||
buf_name = vim.current.buffer.name
|
buf_name = vim.current.buffer.name
|
||||||
file_path = pathlib.Path(buf_name).resolve()
|
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))
|
logger.info(dict(modeline=entry))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user