Skip to content

Commit a832b3c

Browse files
committed
Add path argument for the workspace temp files
1 parent 7ced70a commit a832b3c

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

Diff for: pylsp/python_lsp.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,7 @@ def _cell_document__definition(self, cellDocument=None, position=None, **_kwargs
634634
with workspace.temp_document(total_source) as random_uri:
635635
definitions = self.definitions(random_uri, position)
636636
for definition in definitions:
637-
# TODO: a better test for if a definition is the random_uri
638-
if random_uri in definition['uri']:
637+
if random_uri == definition['uri']:
639638
# Find the cell the start is in
640639
for cell in cell_list:
641640
# TODO: perhaps it is more correct to check definition['range']['end']['line'] <= cell['line_end'], but

Diff for: pylsp/workspace.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ def put_notebook_document(self, doc_uri, notebook_type, cells, version=None, met
120120
self._docs[doc_uri] = self._create_notebook_document(doc_uri, notebook_type, cells, version, metadata)
121121

122122
@contextmanager
123-
def temp_document(self, source):
124-
random_uri = str(uuid.uuid4())
123+
def temp_document(self, source, path=None):
124+
if path is None:
125+
path = self.root_path
126+
uri = uris.from_fs_path(os.path.join(path, str(uuid.uuid4())))
125127
try:
126-
self.put_document(random_uri, source)
127-
yield random_uri
128+
self.put_document(uri, source)
129+
yield uri
128130
finally:
129-
self.rm_document(random_uri)
130-
131-
131+
self.rm_document(uri)
132132

133133
def add_notebook_cells(self, doc_uri, cells, start):
134134
self._docs[doc_uri].add_cells(cells, start)

0 commit comments

Comments
 (0)