Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion pyls/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import re
import sys
from urllib.parse import urlparse, urlunparse, unquote
from urllib.parse import urlparse, urlunparse, quote, unquote

import jedi

Expand Down Expand Up @@ -181,5 +181,10 @@ def get_uri_like(doc_uri, path):
unicode objects.
"""
parts = list(urlparse(doc_uri))
if path[0] != '/' and ':' in path: # fix path for windows
drivespec, path = path.split(':', 1)
path = '/' + drivespec + ':' + quote(path.replace('\\', '/'))
else:
path = quote(path)
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:/hello%20world.py'
win_doc_path = r'D:\hello world.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