Skip to content

Commit ec3ecd0

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 #301 [1]. [1] #301
1 parent 2305b3a commit ec3ecd0

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

Diff for: pylsp/plugins/symbols.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import logging
55
import os
6+
from pathlib import Path
67

78
from pylsp import hookimpl
89
from pylsp.lsp import SymbolKind
@@ -91,14 +92,7 @@ def pylsp_document_symbols(config, document):
9192
else:
9293
continue
9394

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:
95+
if _include_def(d) and Path(document.path) == d.module_path:
10296
tuple_range = _tuple_range(d)
10397
if tuple_range in exclude:
10498
continue

0 commit comments

Comments
 (0)