Skip to content

Commit f87a718

Browse files
rayangleri80and
authored andcommitted
DOCSP-5967: Clicking on an include or directive path opens file
1 parent a1a72ad commit f87a718

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add `textDocument/resolve` RPC endpoint to return the source file path of an artifact relative to the project's root (DOCSP-5967).
13+
1014
## [v0.1.8] - 2019-06-27
1115

1216
### Added

snooty/language_server.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def m_initialize(
225225
self,
226226
processId: Optional[int] = None,
227227
rootUri: Optional[Uri] = None,
228-
**kwargs: object
228+
**kwargs: object,
229229
) -> SerializableType:
230230
if rootUri:
231231
root_path = Path(rootUri.replace("file://", "", 1))
@@ -259,6 +259,16 @@ def m_initialized(self, **kwargs: object) -> None:
259259
# Ignore this message to avoid logging a pointless warning
260260
pass
261261

262+
def m_text_document__resolve(self, path: str) -> str:
263+
"""Given an artifact's path relative to the project's source directory,
264+
return a corresponding source file path relative to the project's root."""
265+
266+
if self.project is None:
267+
logger.warn("Project uninitialized")
268+
return path
269+
270+
return str(self.project.config.source_path) + path
271+
262272
def m_text_document__did_open(self, textDocument: SerializableType) -> None:
263273
if not self.project:
264274
return

snooty/test_language_server.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,20 @@ def test_workspace_entry() -> None:
6868

6969

7070
def test_language_server() -> None:
71-
server = language_server.LanguageServer(sys.stdin.buffer, sys.stdout.buffer)
72-
assert server.uri_to_path("file://foo.rst") == Path("foo.rst")
71+
with language_server.LanguageServer(sys.stdin.buffer, sys.stdout.buffer) as server:
72+
assert server.uri_to_path("file://foo.rst") == Path("foo.rst")
73+
74+
75+
def test_text_doc_resolve() -> None:
76+
"""Tests to see if m_text_document__resolve() returns the proper path combined with """
77+
with language_server.LanguageServer(sys.stdin.buffer, sys.stdout.buffer) as server:
78+
server.m_initialize(None, "file://test_data/test_project")
79+
80+
test_file = "/images/compass-create-database.png"
81+
82+
assert server.project is not None
83+
84+
assert (
85+
server.m_text_document__resolve(test_file)
86+
== str(server.project.config.source_path) + test_file
87+
)

0 commit comments

Comments
 (0)