Skip to content

Commit efc6821

Browse files
committed
Fix symbols for non-existing (unsaved) files
Fix `textDocument/documentSymbols` returning an empty result for non-existing (unsaved) files: Do not use `os.path.samefile()` which accesses the file system to check if two file paths point to the same file. Just compare the file paths. (This basically reverts commit 40afab3.) This fixes issue python-lsp#301 [1]. [1] python-lsp#301
1 parent 2305b3a commit efc6821

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

pylsp/plugins/symbols.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright 2021- Python Language Server Contributors.
33

44
import logging
5-
import os
5+
from pathlib import Path
66

77
from pylsp import hookimpl
88
from pylsp.lsp import SymbolKind
@@ -91,14 +91,7 @@ def pylsp_document_symbols(config, document):
9191
else:
9292
continue
9393

94-
try:
95-
docismodule = os.path.samefile(document.path, d.module_path)
96-
except (TypeError, FileNotFoundError):
97-
# Python 2 on Windows has no .samefile, but then these are
98-
# strings for sure
99-
docismodule = document.path == d.module_path
100-
101-
if _include_def(d) and docismodule:
94+
if _include_def(d) and Path(document.path) == d.module_path:
10295
tuple_range = _tuple_range(d)
10396
if tuple_range in exclude:
10497
continue

0 commit comments

Comments
 (0)