@@ -73,9 +73,87 @@ goto_definition(Uri, [POI | Rest]) ->
73
73
end .
74
74
75
75
-spec match_incomplete (binary (), pos ()) -> [els_poi :poi ()].
76
- match_incomplete (Text , Pos ) ->
76
+ match_incomplete (Text , { Line , Col } = Pos ) ->
77
77
% % Try parsing subsets of text to find a matching POI at Pos
78
- match_after (Text , Pos ) ++ match_line (Text , Pos ).
78
+ case match_after (Text , Pos ) ++ match_line (Text , Pos ) of
79
+ [] ->
80
+ % % Still found nothing, let's analyze the tokens to kludge a POI
81
+ LineText = els_text :line (Text , Line ),
82
+ Tokens = els_text :tokens (LineText , {Line , 1 }),
83
+ kludge_match (Tokens , {Line , Col + 1 });
84
+ POIs ->
85
+ POIs
86
+ end .
87
+
88
+ -spec kludge_match ([any ()], pos ()) -> [els_poi :poi ()].
89
+ kludge_match ([], _Pos ) ->
90
+ [];
91
+ kludge_match (
92
+ [
93
+ {atom , {FromL , FromC }, Module },
94
+ {':' , _ },
95
+ {atom , _ , Function },
96
+ {'(' , {ToL , ToC }}
97
+ | _
98
+ ],
99
+ {_ , C }
100
+ ) when
101
+ FromC =< C , C < ToC
102
+ ->
103
+ % % Match mod:fun(
104
+ Range = #{from => {FromL , FromC }, to => {ToL , ToC }},
105
+ POI = els_poi :new (Range , application , {Module , Function , any_arity }),
106
+ [POI ];
107
+ kludge_match ([{atom , {FromL , FromC }, Function }, {'(' , {ToL , ToC }} | _ ], {_ , C }) when
108
+ FromC =< C , C < ToC
109
+ ->
110
+ % % Match fun(
111
+ Range = #{from => {FromL , FromC }, to => {ToL , ToC }},
112
+ POI = els_poi :new (Range , application , {Function , any_arity }),
113
+ [POI ];
114
+ kludge_match ([{'#' , _ }, {atom , {FromL , FromC }, Record } | T ], {_ , C } = Pos ) when
115
+ FromC =< C
116
+ ->
117
+ % % Match #record
118
+ ToC = FromC + length (atom_to_list (Record )),
119
+ case C =< ToC of
120
+ true ->
121
+ Range = #{from => {FromL , FromC }, to => {FromL , ToC }},
122
+ POI = els_poi :new (Range , record_expr , Record ),
123
+ [POI ];
124
+ false ->
125
+ kludge_match (T , Pos )
126
+ end ;
127
+ kludge_match ([{'?' , _ }, {VarOrAtom , {FromL , FromC }, Macro } | T ], {_ , C } = Pos ) when
128
+ FromC =< C , (VarOrAtom == var orelse VarOrAtom == atom )
129
+ ->
130
+ % % Match ?MACRO
131
+ ToC = FromC + length (atom_to_list (Macro )),
132
+ case C =< ToC of
133
+ true ->
134
+ % % Match fun(
135
+ Range = #{from => {FromL , FromC }, to => {FromL , ToC }},
136
+ POI = els_poi :new (Range , macro , Macro ),
137
+ [POI ];
138
+ false ->
139
+ kludge_match (T , Pos )
140
+ end ;
141
+ kludge_match ([{atom , {FromL , FromC }, Atom } | T ], {_ , C } = Pos ) when
142
+ FromC =< C
143
+ ->
144
+ % % Match atom
145
+ ToC = FromC + length (atom_to_list (Atom )),
146
+ case C =< ToC of
147
+ true ->
148
+ Range = #{from => {FromL , FromC }, to => {FromL , ToC }},
149
+ POI = els_poi :new (Range , atom , Atom ),
150
+ [POI ];
151
+ false ->
152
+ kludge_match (T , Pos )
153
+ end ;
154
+ kludge_match ([_ | T ], Pos ) ->
155
+ % % TODO: Add more kludges here
156
+ kludge_match (T , Pos ).
79
157
80
158
-spec match_after (binary (), pos ()) -> [els_poi :poi ()].
81
159
match_after (Text , {Line , Character }) ->
0 commit comments