Skip to content
This repository was archived by the owner on Mar 27, 2019. It is now read-only.

Commit 0c3da1b

Browse files
committed
wip
1 parent 66417ef commit 0c3da1b

File tree

6 files changed

+52
-88
lines changed

6 files changed

+52
-88
lines changed

Pipfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ opentracing = "*"
1212
lightstep = "*"
1313
"delegator.py" = "*"
1414
pipenv = "*"
15-
jedi = {git = "git://github.com/sourcegraph/jedi.git", editable = true, ref = "dee138a06ce5568bfda1f88d77184223c5cf5b8d"}
15+
jedi = {git = "git://github.com/davidhalter/jedi.git", editable = true, ref = "3c9aa9ef254dbf1aa5f55ed3a4ed9ec4c6d0bb5a"}
1616

1717

1818
[dev-packages]

Pipfile.lock

+20-55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

langserver/clone_workspace.py

+16-24
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import json
99
from functools import lru_cache
1010
from enum import Enum
11-
import pathlib
11+
from pathlib import Path
1212

1313
log = logging.getLogger(__name__)
1414

@@ -19,7 +19,7 @@ def __init__(self, fs: FileSystem, project_root: str,
1919
original_root_path: str= ""):
2020

2121
self.fs = fs
22-
self.PROJECT_ROOT = project_root
22+
self.PROJECT_ROOT = Path(project_root)
2323
self.repo = None
2424
self.hash = None
2525

@@ -39,30 +39,27 @@ def __init__(self, fs: FileSystem, project_root: str,
3939
if self.hash:
4040
self.key = ".".join((self.key, self.hash))
4141

42-
self.PYTHON_PATH = os.path.abspath(GlobalConfig.PYTHON_PATH)
43-
self.CLONED_PROJECT_PATH = os.path.abspath(os.path.join(
44-
GlobalConfig.CLONED_PROJECT_PATH, self.key))
42+
self.CLONED_PROJECT_PATH = GlobalConfig.CLONED_PROJECT_PATH / self.key
4543

46-
log.debug("Setting Python path to %s", self.PYTHON_PATH)
4744
log.debug("Setting Cloned Project path to %s",
4845
self.CLONED_PROJECT_PATH)
4946

5047
# Clone the project from the provided filesystem into the local
5148
# cache
52-
all_files = self.fs.walk(self.PROJECT_ROOT)
53-
for file_path in all_files:
54-
cache_file_path = self.project_to_cache_path(file_path)
49+
for file_path in self.fs.walk(str(self.PROJECT_ROOT)):
5550

56-
os.makedirs(os.path.dirname(cache_file_path), exist_ok=True)
51+
cache_file_path = self.CLONED_PROJECT_PATH / file_path.lstrip("/")
52+
53+
cache_file_path.parent.mkdir(parents=True, exist_ok=True)
5754
file_contents = self.fs.open(file_path)
58-
with open(cache_file_path, "w") as f:
59-
f.write(file_contents)
55+
cache_file_path.write_text(file_contents)
6056

6157
@property
6258
@lru_cache()
63-
def VENV_LOCATION(self):
59+
def VENV_PATH(self):
6460
self.ensure_venv_created()
65-
return self.run_command("pipenv --venv").out.rstrip()
61+
venv_path = self.run_command("pipenv --venv").out.rstrip()
62+
return Path(venv_path)
6663

6764
def cleanup(self):
6865
log.info("Removing project's virtual environment %s", self.VENV_LOCATION)
@@ -106,16 +103,15 @@ def remove_venv(self):
106103
self.run_command("pipenv --rm", no_prefix=True)
107104

108105
def get_module_info(self, raw_module_path):
109-
module_path = pathlib.Path(raw_module_path)
106+
module_path = Path(raw_module_path)
110107

111-
import pdb
112-
pdb.set_trace()
108+
if self.CLONED_PROJECT_PATH in module_path.parents:
109+
return (ModuleKind.PROJECT, module_path.relative_to(self.CLONED_PROJECT_PATH))
113110

114-
sys_std_lib_path = pathlib.Path(self.PYTHON_PATH)
115-
if sys_std_lib_path in module_path.parents:
111+
if GlobalConfig.PYTHON_PATH in module_path.parents:
116112
return (ModuleKind.STANDARD_LIBRARY, path.relative_to(sys_std_lib_path))
117113

118-
venv_path = pathlib.Path(self.VENV_LOCATION) / "lib"
114+
venv_path = self.VENV_LOCATION / "lib"
119115
if venv_path in module_path.parents:
120116
# The python libraries in a venv are stored under
121117
# VENV_LOCATION/lib/(some_python_version)
@@ -129,10 +125,6 @@ def get_module_info(self, raw_module_path):
129125
return (ModuleKind.EXTERNAL_DEPENDENCY, module_path.relative_to(venv_ext_packages_path))
130126
return (ModuleKind.STANDARD_LIBRARY, module_path.relative_to(venv_lib_path))
131127

132-
project_path = pathlib.Path(self.CLONED_PROJECT_PATH)
133-
if project_path in module_path.parents:
134-
return (ModuleKind.PROJECT, module_path.relative_to(project_path))
135-
136128
return (ModuleKind.UNKNOWN, module_path)
137129

138130
def get_package_information(self):

langserver/config.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import distutils
1+
from distutils.sysconfig import get_python_lib
2+
from pathlib import Path
23

34

45
class GlobalConfig:
56

67
# TODO: allow different Python stdlib versions per workspace?
78

8-
PYTHON_PATH = distutils.sysconfig.get_python_lib(standard_lib=True)
9-
PACKAGES_PARENT = "python-langserver-cache"
10-
CLONED_PROJECT_PATH = "python-cloned-projects-cache"
9+
PYTHON_PATH = Path(get_python_lib(standard_lib=True)).absolute()
10+
PACKAGES_PARENT = Path("python-langserver-cache").absolute()
11+
CLONED_PROJECT_PATH = Path("python-cloned-projects-cache").absolute()
1112
STDLIB_REPO_URL = "git://github.com/python/cpython"
12-
STDLIB_SRC_PATH = "Lib"
13+
STDLIB_SRC_PATH = Path("Lib")

langserver/jedi.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@ def _new_script_impl(self, parent_span, *args, **kwargs):
3333

3434
if self.workspace is not None:
3535
path = self.workspace.project_to_cache_path(path)
36-
venv_path = self.workspace.VENV_LOCATION
36+
37+
environment = None
38+
for env in jedi.find_virtualenvs([self.workspace.VENV_PATH], safe=False):
39+
if env._base_path == self.workspace.VENV_PATH:
40+
environment = env
41+
break
3742

3843
kwargs.update(
39-
venv_path=venv_path,
44+
environment=environment,
4045
path=path
4146
)
4247

langserver/langserver.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ def serve_x_definition(self, request):
358358
if kind is not ModuleKind.UNKNOWN:
359359
if kind == ModuleKind.STANDARD_LIBRARY:
360360
filename = module_path.name
361+
module_path = GlobalConfig.STDLIB_SRC_PATH / module_path
361362
symbol_name = ""
362363
symbol_kind = ""
363364
if d.description:
@@ -370,7 +371,7 @@ def serve_x_definition(self, request):
370371
"name": symbol_name,
371372
"container": d.full_name,
372373
"kind": symbol_kind,
373-
"path": str(GlobalConfig.STDLIB_SRC_PATH / module_path),
374+
"path": str(module_path),
374375
"file": filename
375376
}
376377
else:

0 commit comments

Comments
 (0)