Skip to content

Commit 0c2a08f

Browse files
committed
fix(langserver): single resource file with different relative paths is not seen as same file
fixes #173
1 parent 52fa94a commit 0c2a08f

File tree

5 files changed

+32
-34
lines changed

5 files changed

+32
-34
lines changed

packages/core/src/robotcode/core/uri.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,6 @@ def __iter__(self) -> Iterator[str]:
181181

182182
def normalized(self) -> Uri:
183183
if self.scheme == "file":
184-
return Uri.from_path(self.to_path().absolute())
184+
return Uri.from_path(self.to_path().resolve())
185185

186186
return Uri(str(self))

packages/debugger/src/robotcode/debugger/listeners.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ def log_message(self, message: Dict[str, Any]) -> None:
142142
item_id = next(
143143
(
144144
(
145-
f"{Path(item.source).absolute() if item.source is not None else ''};{item.longname}"
145+
f"{Path(item.source).resolve() if item.source is not None else ''};{item.longname}"
146146
if item.type == "SUITE"
147-
else f"{Path(item.source).absolute() if item.source is not None else ''};"
147+
else f"{Path(item.source).resolve() if item.source is not None else ''};"
148148
f"{item.longname};{item.line}"
149149
)
150150
for item in Debugger.instance().full_stack_frames
@@ -189,9 +189,9 @@ def message(self, message: Dict[str, Any]) -> None:
189189
item_id = next(
190190
(
191191
(
192-
f"{Path(item.source).absolute() if item.source is not None else ''};{item.longname}"
192+
f"{Path(item.source).resolve() if item.source is not None else ''};{item.longname}"
193193
if item.type == "SUITE"
194-
else f"{Path(item.source).absolute() if item.source is not None else ''};"
194+
else f"{Path(item.source).resolve() if item.source is not None else ''};"
195195
f"{item.longname};{item.line}"
196196
)
197197
for item in Debugger.instance().full_stack_frames
@@ -264,15 +264,15 @@ def start_suite(self, data: running.TestSuite, result: result.TestSuite) -> None
264264

265265
def enqueue(item: Union[running.TestSuite, running.TestCase]) -> Iterator[str]:
266266
if isinstance(item, running.TestSuite):
267-
yield f"{Path(item.source).absolute() if item.source is not None else ''};{item.longname}"
267+
yield f"{Path(item.source).resolve() if item.source is not None else ''};{item.longname}"
268268

269269
for s in item.suites:
270270
yield from enqueue(s)
271271
for s in item.tests:
272272
yield from enqueue(s)
273273
return
274274

275-
yield f"{Path(item.source).absolute() if item.source is not None else ''};{item.longname};{item.lineno}"
275+
yield f"{Path(item.source).resolve() if item.source is not None else ''};{item.longname};{item.lineno}"
276276

277277
if self._event_sended:
278278
return

packages/language_server/src/robotcode/language_server/robotframework/diagnostics/imports_manager.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ async def check_file_changed(self, changes: List[FileEvent]) -> Optional[FileCha
190190
self._lib_doc.module_spec is not None
191191
and self._lib_doc.module_spec.submodule_search_locations is not None
192192
and any(
193-
path_is_relative_to(path, Path(e).absolute())
193+
path_is_relative_to(path, Path(e).resolve())
194194
for e in self._lib_doc.module_spec.submodule_search_locations
195195
)
196196
)
@@ -204,7 +204,7 @@ async def check_file_changed(self, changes: List[FileEvent]) -> Optional[FileCha
204204
self._lib_doc.module_spec is None
205205
and not self._lib_doc.source
206206
and self._lib_doc.python_path
207-
and any(path_is_relative_to(path, Path(e).absolute()) for e in self._lib_doc.python_path)
207+
and any(path_is_relative_to(path, Path(e).resolve()) for e in self._lib_doc.python_path)
208208
)
209209
):
210210
await self._invalidate()
@@ -230,14 +230,14 @@ async def _update(self) -> None:
230230
await self.parent.parent_protocol.workspace.add_file_watchers(
231231
self.parent.did_change_watched_files,
232232
[
233-
str(Path(location).absolute().joinpath("**"))
233+
str(Path(location).resolve().joinpath("**"))
234234
for location in self._lib_doc.module_spec.submodule_search_locations
235235
],
236236
)
237237
)
238238

239239
if source_or_origin is not None and Path(source_or_origin).parent in [
240-
Path(loc).absolute() for loc in self._lib_doc.module_spec.submodule_search_locations
240+
Path(loc).resolve() for loc in self._lib_doc.module_spec.submodule_search_locations
241241
]:
242242
return
243243

@@ -315,7 +315,7 @@ async def check_file_changed(self, changes: List[FileEvent]) -> Optional[FileCha
315315
path = uri.to_path()
316316
if (
317317
self._document is not None
318-
and (path.absolute() == self._document.uri.to_path().absolute())
318+
and (path.resolve() == self._document.uri.to_path().resolve())
319319
or self._document is None
320320
):
321321
await self._invalidate()
@@ -423,11 +423,7 @@ async def check_file_changed(self, changes: List[FileEvent]) -> Optional[FileCha
423423
continue
424424

425425
path = uri.to_path()
426-
if (
427-
self._lib_doc.source
428-
and path.exists()
429-
and path.absolute().samefile(Path(self._lib_doc.source).absolute())
430-
):
426+
if self._lib_doc.source and path.exists() and path.samefile(Path(self._lib_doc.source)):
431427
await self._invalidate()
432428

433429
return change.type
@@ -859,14 +855,14 @@ async def get_library_meta(
859855
return None, import_name
860856

861857
if result.origin is not None:
862-
result.mtimes = {result.origin: Path(result.origin).absolute().stat().st_mtime_ns}
858+
result.mtimes = {result.origin: Path(result.origin).stat().st_mtime_ns}
863859

864860
if result.submodule_search_locations:
865861
if result.mtimes is None:
866862
result.mtimes = {}
867863
result.mtimes.update(
868864
{
869-
str(f): f.absolute().stat().st_mtime_ns
865+
str(f): f.stat().st_mtime_ns
870866
for f in itertools.chain(
871867
*(iter_files(loc, "**/*.py") for loc in result.submodule_search_locations)
872868
)
@@ -928,14 +924,14 @@ async def get_variables_meta(
928924
return None, import_name
929925

930926
if result.origin is not None:
931-
result.mtimes = {result.origin: Path(result.origin).absolute().stat().st_mtime_ns}
927+
result.mtimes = {result.origin: Path(result.origin).stat().st_mtime_ns}
932928

933929
if result.submodule_search_locations:
934930
if result.mtimes is None:
935931
result.mtimes = {}
936932
result.mtimes.update(
937933
{
938-
str(f): f.absolute().stat().st_mtime_ns
934+
str(f): f.stat().st_mtime_ns
939935
for f in itertools.chain(
940936
*(iter_files(loc, "**/*.py") for loc in result.submodule_search_locations)
941937
)
@@ -1309,7 +1305,7 @@ async def _get_entry_for_resource_import(
13091305
async def _get_document() -> TextDocument:
13101306
self._logger.debug(lambda: f"Load resource {name} from source {source}")
13111307

1312-
source_path = Path(source).absolute()
1308+
source_path = Path(source).resolve()
13131309
extension = source_path.suffix
13141310
if extension.lower() not in RESOURCE_EXTENSIONS:
13151311
raise ImportError(

packages/language_server/src/robotcode/language_server/robotframework/diagnostics/library_doc.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ def _get_default_variables() -> Any:
13271327
if __default_variables is None:
13281328
__default_variables = Variables()
13291329
for k, v in {
1330-
"${TEMPDIR}": str(Path(tempfile.gettempdir()).absolute()),
1330+
"${TEMPDIR}": str(Path(tempfile.gettempdir()).resolve()),
13311331
"${/}": os.sep,
13321332
"${:}": os.pathsep,
13331333
"${\\n}": os.linesep,
@@ -1376,8 +1376,8 @@ def resolve_robot_variables(
13761376
result: Variables = _get_default_variables().copy()
13771377

13781378
for k, v in {
1379-
"${CURDIR}": str(Path(base_dir).absolute()),
1380-
"${EXECDIR}": str(Path(working_dir).absolute()),
1379+
"${CURDIR}": str(Path(base_dir).resolve()),
1380+
"${EXECDIR}": str(Path(working_dir).resolve()),
13811381
}.items():
13821382
result[k] = v
13831383

@@ -2207,9 +2207,11 @@ def complete_library_import(
22072207
if name is None or (is_file_like(name) and (name.endswith(("/", os.sep)))):
22082208
name_path = Path(name if name else base_dir)
22092209
if name_path.is_absolute():
2210-
path = name_path.absolute()
2210+
path = name_path
22112211
else:
2212-
path = Path(base_dir, name if name else base_dir).absolute()
2212+
path = Path(base_dir, name) if name else Path(base_dir)
2213+
2214+
path = path.resolve()
22132215

22142216
if path.exists() and path.is_dir():
22152217
result += [
@@ -2270,9 +2272,9 @@ def complete_resource_import(
22702272
if name is None or name.startswith((".", "/", os.sep)):
22712273
name_path = Path(name if name else base_dir)
22722274
if name_path.is_absolute():
2273-
path = name_path.absolute()
2275+
path = name_path.resolve()
22742276
else:
2275-
path = Path(base_dir, name if name else base_dir).absolute()
2277+
path = Path(base_dir, name if name else base_dir).resolve()
22762278

22772279
if path.exists() and (path.is_dir()):
22782280
result += [
@@ -2366,9 +2368,9 @@ def complete_variables_import(
23662368
if name is None or name.startswith((".", "/", os.sep)):
23672369
name_path = Path(name if name else base_dir)
23682370
if name_path.is_absolute():
2369-
path = name_path.absolute()
2371+
path = name_path.resolve()
23702372
else:
2371-
path = Path(base_dir, name if name else base_dir).absolute()
2373+
path = Path(base_dir, name if name else base_dir).resolve()
23722374

23732375
if path.exists() and (path.is_dir()):
23742376
result += [

packages/runner/src/robotcode/runner/cli/discover/discover.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def visit_suite(self, suite: TestSuite) -> None:
256256
self._collected[-1][suite.name] = True
257257
self._collected.append(NormalizedDict(ignore="_"))
258258
try:
259-
absolute_path = Path(suite.source).absolute() if suite.source else None
259+
absolute_path = Path(suite.source).resolve() if suite.source else None
260260
item = TestItem(
261261
type="suite",
262262
id=f"{absolute_path or ''};{suite.longname}",
@@ -309,7 +309,7 @@ def visit_test(self, test: TestCase) -> None:
309309
if self._current.children is None:
310310
self._current.children = []
311311
try:
312-
absolute_path = Path(test.source).absolute() if test.source is not None else None
312+
absolute_path = Path(test.source).resolve() if test.source is not None else None
313313
item = TestItem(
314314
type="test",
315315
id=f"{absolute_path or ''};{test.longname};{test.lineno}",
@@ -386,7 +386,7 @@ def add_diagnostic(
386386
line: Optional[int] = None,
387387
text: Optional[str] = None,
388388
) -> None:
389-
source_uri = str(Uri.from_path(Path(source_uri).absolute() if source_uri else Path.cwd()))
389+
source_uri = str(Uri.from_path(Path(source_uri).resolve() if source_uri else Path.cwd()))
390390

391391
if source_uri not in result:
392392
result[source_uri] = []

0 commit comments

Comments
 (0)