Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyls/plugins/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ def pyls_definitions(document, position):
d for d in definitions
if d.is_definition() and d.line is not None and d.column is not None
]

return [{
'uri': workspace.get_uri_like(document.uri, d.module_path),
'uri': workspace.get_uri_like(document.uri, d.module_path) if d.module_path else document.uri,
'range': {
'start': {'line': d.line - 1, 'character': d.column},
'end': {'line': d.line - 1, 'character': d.column + len(d.name)}
Expand Down
2 changes: 1 addition & 1 deletion pyls/plugins/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def pyls_references(document, position, exclude_declaration=False):
usages = [d for d in usages if not d.is_definition()]

return [{
'uri': workspace.get_uri_like(document.uri, d.module_path),
'uri': workspace.get_uri_like(document.uri, d.module_path) if d.module_path else document.uri,
'range': {
'start': {'line': d.line - 1, 'character': d.column},
'end': {'line': d.line - 1, 'character': d.column + len(d.name)}
Expand Down
2 changes: 2 additions & 0 deletions pyls/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,7 @@ def get_uri_like(doc_uri, path):
unicode objects.
"""
parts = list(urlparse(doc_uri))
if path[0] != '/': # fix path for windows
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add and ':' in path just to make sure we don't throw on the next line

path = '/' + path.replace('\\', '/')
parts[2] = path
return urlunparse([str(p) for p in parts])
4 changes: 4 additions & 0 deletions test/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def test_bad_get_document(pyls):

def test_uri_like():
assert workspace.get_uri_like('file:///some-path', '/my/path') == 'file:///my/path'
win_doc_uri = r'file:///D:/helloworld.py'
win_doc_path = r'D:\helloworld.py'
win_uri = workspace.get_uri_like(win_doc_uri, win_doc_path)
assert win_uri == win_doc_uri


def test_non_root_project(pyls):
Expand Down