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

Commit 2826abb

Browse files
committed
delete a lot of the xdef logic for now, use cloneworkspace outside test
1 parent bbe5a09 commit 2826abb

File tree

1 file changed

+33
-72
lines changed

1 file changed

+33
-72
lines changed

langserver/langserver.py

Lines changed: 33 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,16 @@ def serve_initialize(self, request):
172172
if isinstance(p, list):
173173
pip_args = p
174174
else:
175-
log.error("pipArgs (%s) found, but was not a list, so ignoring", str(p))
175+
log.error(
176+
"pipArgs (%s) found, but was not a list, so ignoring", str(p))
176177

177178
# Sourcegraph also passes in a rootUri which has commit information
178179
originalRootUri = params.get("originalRootUri") or params.get(
179180
"originalRootPath") or ""
180-
self.workspace = Workspace(self.fs, self.root_path, originalRootUri, pip_args)
181+
# self.workspace = Workspace(
182+
# self.fs, self.root_path, originalRootUri, pip_args)
183+
self.workspace = CloneWorkspace(
184+
self.fs, self.root_path, originalRootUri)
181185

182186
return {
183187
"capabilities": {
@@ -354,83 +358,39 @@ def serve_x_definition(self, request):
354358
return results
355359

356360
for d in defs:
357-
kind, module_path = ModuleKind.UNKNOWN, ""
358-
if d.module_path:
359-
kind, module_path = self.workspace.get_module_info(
360-
d.module_path)
361+
# TODO: handle case where a def doesn't have a module_path
362+
if not d.module_path:
363+
continue
364+
365+
module_kind, rel_module_path = self.workspace.get_module_info(
366+
d.module_path)
367+
368+
if module_kind != ModuleKind.PROJECT:
369+
# only handle internal defs for now
370+
continue
361371

362372
if (not d.is_definition() or
363373
d.line is None or d.column is None):
364374
continue
365375

366-
symbol_locator = {"symbol": None, "location": None}
367-
368-
if kind is not ModuleKind.UNKNOWN:
369-
if kind == ModuleKind.STANDARD_LIBRARY:
370-
filename = module_path.name
371-
module_path = GlobalConfig.STDLIB_SRC_PATH / module_path
372-
symbol_name = ""
373-
symbol_kind = ""
374-
if d.description:
375-
symbol_name, symbol_kind = LangServer.name_and_kind(
376-
d.description)
377-
symbol_locator["symbol"] = {
378-
"package": {
379-
"name": "cpython",
380-
},
381-
"name": symbol_name,
382-
"container": d.full_name,
383-
"kind": symbol_kind,
384-
"path": str(module_path),
385-
"file": filename
386-
}
387-
else:
388-
# the module path doesn't map onto the repository structure
389-
# because we're not fully installing
390-
# dependency packages, so don't include it in the symbol
391-
# descriptor
392-
filename = module_path.name
393-
symbol_name = ""
394-
symbol_kind = ""
395-
if d.description:
396-
symbol_name, symbol_kind = LangServer.name_and_kind(
397-
d.description)
398-
symbol_locator["symbol"] = {
399-
"package": {
400-
"name": d.full_name.split(".")[0],
401-
},
402-
"name": symbol_name,
403-
"container": d.full_name,
404-
"kind": symbol_kind,
405-
"file": filename
406-
}
376+
location = {
377+
# put a "/" shim at the front to make the path
378+
# seem like an absolute one inside the project
379+
"uri": "file://" + str("/" / rel_module_path),
407380

408-
if (d.is_definition() and
409-
d.line is not None and d.column is not None):
410-
location = {
411-
# TODO(renfred) determine why d.module_path is empty.
412-
"uri": "file://" + (str(module_path) or path),
413-
"range": {
414-
"start": {
415-
"line": d.line - 1,
416-
"character": d.column,
417-
},
418-
"end": {
419-
"line": d.line - 1,
420-
"character": d.column + len(d.name),
421-
},
381+
"range": {
382+
"start": {
383+
"line": d.line - 1,
384+
"character": d.column,
422385
},
423-
}
424-
# add a position hint in case this eventually gets passed to an
425-
# operation that could use it
426-
if symbol_locator["symbol"]:
427-
symbol_locator["symbol"]["position"] = location["range"][
428-
"start"]
429-
430-
# set the full location if the definition is in this workspace
431-
if not kind in [ModuleKind.UNKNOWN, ModuleKind.EXTERNAL_DEPENDENCY]:
432-
symbol_locator["location"] = location
386+
"end": {
387+
"line": d.line - 1,
388+
"character": d.column + len(d.name),
389+
},
390+
},
391+
}
433392

393+
symbol_locator = {"symbol": None, "location": location}
434394
results.append(symbol_locator)
435395

436396
unique_results = []
@@ -701,7 +661,8 @@ def main():
701661
parser.add_argument(
702662
"--addr", default=4389, help="server listen (tcp)", type=int)
703663
parser.add_argument("--debug", action="store_true")
704-
parser.add_argument("--lightstep_token", default=os.environ.get("LIGHTSTEP_ACCESS_TOKEN"))
664+
parser.add_argument("--lightstep_token",
665+
default=os.environ.get("LIGHTSTEP_ACCESS_TOKEN"))
705666
parser.add_argument("--python_path")
706667

707668
args = parser.parse_args()

0 commit comments

Comments
 (0)