Skip to content

Commit 4e33e83

Browse files
grievejiafacebook-github-bot
authored andcommitted
Avoid returning full paths for types() query
Reviewed By: dkgi Differential Revision: D30146026 fbshipit-source-id: b5b955dfdb7883ac95fd7c4309067885bde41e56
1 parent 12fd6a1 commit 4e33e83

File tree

5 files changed

+37
-41
lines changed

5 files changed

+37
-41
lines changed

source/new_server/lookupProcessor.ml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@
88
open Core
99
open Ast
1010
open Analysis
11+
module Path = PyrePath
1112

1213
type error_reason =
1314
| StubShadowing
1415
| FileNotFound
1516

1617
type types_by_path = {
17-
path: PyrePath.t;
18+
path: string;
1819
types_by_location: ((Location.t * Type.t) list, error_reason) Result.t;
1920
}
2021

2122
type lookup = {
22-
path: PyrePath.t;
23+
path: string;
2324
lookup: (Lookup.t, error_reason) Result.t;
2425
}
2526

@@ -32,8 +33,12 @@ let get_lookups ~configuration ~build_system:_ ~environment paths =
3233
{ path; lookup = Result.Error error_reason }
3334
in
3435
let generate_lookup_for_path path =
36+
let full_path =
37+
let { Configuration.Analysis.local_root = root; _ } = configuration in
38+
Path.create_relative ~root ~relative:path
39+
in
3540
let module_tracker = TypeEnvironment.module_tracker environment in
36-
match ModuleTracker.lookup_path ~configuration module_tracker path with
41+
match ModuleTracker.lookup_path ~configuration module_tracker full_path with
3742
| ModuleTracker.PathLookup.Found source_path ->
3843
generate_lookup_for_existent_path (path, source_path)
3944
| ModuleTracker.PathLookup.ShadowedBy _ ->
@@ -43,7 +48,7 @@ let get_lookups ~configuration ~build_system:_ ~environment paths =
4348
List.map paths ~f:generate_lookup_for_path
4449

4550

46-
let find_all_annotations_batch ~environment ~build_system ~configuration ~paths =
51+
let find_all_annotations_batch ~environment ~build_system ~configuration paths =
4752
let get_annotations { path; lookup; _ } =
4853
{
4954
path;

source/new_server/lookupProcessor.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type error_reason =
1313
| FileNotFound
1414

1515
type types_by_path = {
16-
path: PyrePath.t;
16+
path: string;
1717
types_by_location: ((Location.t * Type.t) list, error_reason) Core.Result.t;
1818
}
1919

@@ -25,5 +25,5 @@ val find_all_annotations_batch
2525
: environment:TypeEnvironment.t ->
2626
build_system:BuildSystem.t ->
2727
configuration:Configuration.Analysis.t ->
28-
paths:PyrePath.t list ->
28+
string list ->
2929
types_by_path list

source/new_server/query.ml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module Response = struct
6363
[@@deriving sexp, compare, to_yojson]
6464

6565
type types_at_path = {
66-
path: PyrePath.t;
66+
path: string;
6767
types: type_at_location list;
6868
}
6969
[@@deriving sexp, compare, to_yojson]
@@ -512,10 +512,9 @@ let rec process_request ~environment ~build_system ~configuration request =
512512
| LookupProcessor.FileNotFound -> " (file not found)"
513513
in
514514
Format.asprintf
515-
"%s%s`%a`%s"
515+
"%s%s`%s`%s"
516516
sofar
517517
(if String.is_empty sofar then "" else ", ")
518-
PyrePath.pp
519518
path
520519
(print_reason error_reason))
521520
errors
@@ -719,16 +718,8 @@ let rec process_request ~environment ~build_system ~configuration request =
719718
let annotation = Resolution.resolve_expression_to_type resolution expression in
720719
Single (Type annotation)
721720
| TypesInFiles paths ->
722-
let paths =
723-
let { Configuration.Analysis.local_root = root; _ } = configuration in
724-
List.map ~f:(fun path -> Path.create_relative ~root ~relative:path) paths
725-
in
726721
let annotations =
727-
LookupProcessor.find_all_annotations_batch
728-
~environment
729-
~build_system
730-
~configuration
731-
~paths
722+
LookupProcessor.find_all_annotations_batch ~environment ~build_system ~configuration paths
732723
in
733724
let create_result { LookupProcessor.path; types_by_location } =
734725
match types_by_location with

source/new_server/query.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module Response : sig
5656
[@@deriving sexp, compare, to_yojson]
5757

5858
type types_at_path = {
59-
path: PyrePath.t;
59+
path: string;
6060
types: type_at_location list;
6161
}
6262
[@@deriving sexp, compare, to_yojson]

source/new_server/test/queryTest.ml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -374,12 +374,12 @@ let test_handle_query_basic context =
374374
a = 42
375375
|}
376376
~query:"types(path='test.py')"
377-
(fun local_root ->
377+
(fun _ ->
378378
Single
379379
(Base.TypesByPath
380380
[
381381
{
382-
Base.path = Path.create_relative ~root:local_root ~relative:"test.py";
382+
Base.path = "test.py";
383383
types =
384384
[
385385
( 2,
@@ -434,12 +434,12 @@ let test_handle_query_basic context =
434434
return x
435435
|}
436436
~query:"types(path='test.py')"
437-
(fun local_root ->
437+
(fun _ ->
438438
Single
439439
(Base.TypesByPath
440440
[
441441
{
442-
Base.path = Path.create_relative ~root:local_root ~relative:"test.py";
442+
Base.path = "test.py";
443443
types =
444444
[
445445
( 2,
@@ -492,12 +492,12 @@ let test_handle_query_basic context =
492492
y = 3
493493
|}
494494
~query:"types(path='test.py')"
495-
(fun local_root ->
495+
(fun _ ->
496496
Single
497497
(Base.TypesByPath
498498
[
499499
{
500-
Base.path = Path.create_relative ~root:local_root ~relative:"test.py";
500+
Base.path = "test.py";
501501
types =
502502
[
503503
2, 0, 2, 1, Type.integer;
@@ -516,12 +516,12 @@ let test_handle_query_basic context =
516516
x = 1
517517
|}
518518
~query:"types(path='test.py')"
519-
(fun local_root ->
519+
(fun _ ->
520520
Single
521521
(Base.TypesByPath
522522
[
523523
{
524-
Base.path = Path.create_relative ~root:local_root ~relative:"test.py";
524+
Base.path = "test.py";
525525
types =
526526
[
527527
( 2,
@@ -554,12 +554,12 @@ let test_handle_query_basic context =
554554
y = 1
555555
|}
556556
~query:"types(path='test.py')"
557-
(fun local_root ->
557+
(fun _ ->
558558
Single
559559
(Base.TypesByPath
560560
[
561561
{
562-
Base.path = Path.create_relative ~root:local_root ~relative:"test.py";
562+
Base.path = "test.py";
563563
types =
564564
[
565565
( 2,
@@ -597,12 +597,12 @@ let test_handle_query_basic context =
597597
y = 2
598598
|}
599599
~query:"types(path='test.py')"
600-
(fun local_root ->
600+
(fun _ ->
601601
Single
602602
(Base.TypesByPath
603603
[
604604
{
605-
Base.path = Path.create_relative ~root:local_root ~relative:"test.py";
605+
Base.path = "test.py";
606606
types =
607607
[
608608
( 2,
@@ -636,12 +636,12 @@ let test_handle_query_basic context =
636636
y = 2
637637
|}
638638
~query:"types(path='test.py')"
639-
(fun local_root ->
639+
(fun _ ->
640640
Single
641641
(Base.TypesByPath
642642
[
643643
{
644-
Base.path = Path.create_relative ~root:local_root ~relative:"test.py";
644+
Base.path = "test.py";
645645
types =
646646
[
647647
2, 5, 2, 11, Type.Any;
@@ -659,12 +659,12 @@ let test_handle_query_basic context =
659659
y = 1
660660
|}
661661
~query:"types(path='test.py')"
662-
(fun local_root ->
662+
(fun _ ->
663663
Single
664664
(Base.TypesByPath
665665
[
666666
{
667-
Base.path = Path.create_relative ~root:local_root ~relative:"test.py";
667+
Base.path = "test.py";
668668
types =
669669
[
670670
2, 6, 2, 15, Type.bool;
@@ -685,12 +685,12 @@ let test_handle_query_basic context =
685685
return x
686686
|}
687687
~query:"types(path='test.py')"
688-
(fun local_root ->
688+
(fun _ ->
689689
Single
690690
(Base.TypesByPath
691691
[
692692
{
693-
Base.path = Path.create_relative ~root:local_root ~relative:"test.py";
693+
Base.path = "test.py";
694694
types =
695695
[
696696
( 2,
@@ -735,12 +735,12 @@ let test_handle_query_basic context =
735735
pass
736736
|}
737737
~query:"types(path='test.py')"
738-
(fun local_root ->
738+
(fun _ ->
739739
Single
740740
(Base.TypesByPath
741741
[
742742
{
743-
Base.path = Path.create_relative ~root:local_root ~relative:"test.py";
743+
Base.path = "test.py";
744744
types =
745745
[
746746
( 2,
@@ -780,12 +780,12 @@ let test_handle_query_basic context =
780780
x = 1
781781
|}
782782
~query:"types('test.py')"
783-
(fun local_root ->
783+
(fun _ ->
784784
Single
785785
(Base.TypesByPath
786786
[
787787
{
788-
Base.path = Path.create_relative ~root:local_root ~relative:"test.py";
788+
Base.path = "test.py";
789789
types =
790790
[
791791
{

0 commit comments

Comments
 (0)