1:- module(pls_language_profile_base, [
2
3]). 4
5:- use_module(library(log4p)). 6:- use_module(pls_index).
13pls_index_profiles:profile_index_term(base, URI, Pos, (:- module(Module, Exports))) :-
14 term_position_range(URI, Pos, Range),
15 pls_index:pls_index:add_document_item(URI, Range, module(Module, Exports)),
16 17 argument_positions(Pos, [DirectiveArgPos]),
18 19 argument_positions(DirectiveArgPos, [_,list_position(_,_,ExportPosList, _)]),
20 index_exports(URI, Exports, ExportPosList),
21 !.
22
23pls_index_profiles:profile_index_term(base, URI, Pos, (:- use_module(Module))) :-
24 term_position_range(URI, Pos, Range),
25 pls_index:add_document_item(URI, Range, uses(Module)),
26 !.
27
28pls_index_profiles:profile_index_term(base, URI, Pos, (:- reexport(Module))) :-
29 term_position_range(URI, Pos, Range),
30 pls_index:add_document_item(URI, Range, reexports(Module)),
31 !.
32
33pls_index_profiles:profile_index_term(base, URI, Pos, (:- reexport(Module, Imports))) :-
34 term_position_range(URI, Pos, Range),
35 pls_index:add_document_item(URI, Range, reexports(Module,Imports)),
36 !.
37
38pls_index_profiles:profile_index_term(base, URI, Pos, (:- [FileSpec])) :-
39 term_position_range(URI, Pos, Range),
40 pls_index:add_document_item(URI, Range, loads(FileSpec)),
41 !.
42
43pls_index_profiles:profile_index_term(base, URI, Pos, (:- include(FileSpec) )) :-
44 term_position_range(URI, Pos, Range),
45 pls_index:add_document_item(URI, Range, includes(FileSpec)),
46 !.
47
48pls_index_profiles:profile_index_term(base, URI, Pos, (_Module:Head :- Body)) :-
49 pls_index_profiles:profile_index_term(base, URI, Pos, (Head :- Body)).
50
51pls_index_profiles:profile_index_term(base, URI, _Pos, :- provide_language_profile(Profile) ) :-
52 register_language_profile(Profile, URI),
53 reindex_for_profile(Profile).
54
55pls_index_profiles:profile_index_term(base, URI, Pos, :- Declaration ) :-
56 Declaration =.. [Directive, Arg],
57 member(Directive, [dynamic, multifile, discontiguous]),
58 argument_positions(Pos, [ArgPos]),
59 index_declaration(URI, ArgPos, Directive, Arg).
60
61pls_index_profiles:profile_index_term(base, URI, Pos, (Head :- Body)) :-
62 functor(Head, Name, Arity),
63 Caller = Name/Arity,
64 argument_positions(Pos, [HeadPos, BodyPos]),
65 term_position_range(URI, HeadPos, Range),
66 pls_index:add_document_item(URI, Range, defines(Caller)),
67 index_goals(URI, Caller, BodyPos, Body),
68 !.
69
70pls_index_profiles:profile_index_term(base, URI, Pos, (Head --> Body)) :-
71 functor(Head, Name, Arity),
72 Caller = Name//Arity,
73 argument_positions(Pos, [HeadPos, BodyPos]),
74 term_position_range(URI, HeadPos, Range),
75 pls_index:add_document_item(URI, Range, defines(Caller)),
76 index_goals(URI, Caller, BodyPos, Body),
77 !.
78
79pls_index_profiles:profile_index_term(base, URI, Pos, _Module:Term) :-
80 pls_index_profiles:profile_index_term(base, URI, Pos, Term),
81 !.
82
83pls_index_profiles:profile_index_term(base, URI, Pos, Term) :-
84 functor(Term, Name, Arity),
85 atom_codes(Name, [Initial|_]),
86 code_type(Initial, prolog_atom_start),
87 Caller = Name/Arity,
88 term_position_range(URI, Pos, Range),
89 pls_index:add_document_item(URI, Range, defines(Caller)),
90 !.
91
92pls_index_profiles:profile_index_docs(base, URI, SubPos, _Module:Head :- Body, CommentPos) :-
93 pls_index_profiles:profile_index_docs(base, URI, SubPos, Head :- Body, CommentPos),
94 !.
95
96pls_index_profiles:profile_index_docs(base, URI, SubPos, Head :- _Body, CommentPos) :-
97 term_position_range(URI, SubPos, Range),
98 functor(Head, Name, Arity),
99 Predicate = Name/Arity,
100 index_docs(URI, Predicate, Range, CommentPos),
101 !.
102
103pls_index_profiles:profile_index_docs(base, _URI, _SubPos, _Term, _CommentPos).
104
105pls_index_profiles:profile_index_signature(base, URI, Pos, Head :- _Body, Vars) :-
106 with_output_to(string(Signature),
107 write_term(Head,[variable_names(Vars)])
108 ),
109 term_position_range(URI, Pos, Range),
110 functor(Head, Name, Arity),
111 pls_index:add_document_item(URI, Range, signature(Name/Arity, Signature)).
112
113pls_index_profiles:profile_index_signature(base, _, _, _, _).
114
115pls_index_profiles:profile_index_goal(base, URI, Caller, SubPos, _Module:Goal) :-
116 argument_positions(SubPos, [_ModulePos, GoalPos]),
117 index_goal(URI, Caller, GoalPos, Goal),
118 !.
119
120pls_index_profiles:profile_index_goal(base, URI, Caller, parentheses_term_position(_From, _To, ContentPos), Goal) :-
121 index_goal(URI, Caller, ContentPos, Goal).
122
123pls_index_profiles:profile_index_goal(base, URI, Caller, term_position(_From, _To, FFrom, FTo, _Subpos), Goal) :-
124 functor_range(URI, FFrom, FTo, Range),
125 ( Caller = _Name // _Arity
126 -> ( functor(Goal, Name, Arity), Predicate = Name//Arity)
127 ; ( functor(Goal, Name, Arity), Predicate = Name/Arity)
128 ),
129 130 Name \= ',',
131 Item = references(Caller, Predicate),
132 debug("Adding item %w",[Item]),
133 pls_index:add_document_item(URI, Range, Item) .
134
135pls_index_profiles:profile_index_goal(base, URI, Caller, term_position(_From, _To, _FFrom, _FTo, Subpos), Goal) :-
136 functor(Goal, _Name, Arity),
137 between(1, Arity, Index),
138 arg(Index, Goal, Arg),
139 nth1(Index, Subpos, Pos),
140 index_goal(URI, Caller, Pos, Arg).
141
142pls_index_profiles:profile_end_of_file(base, _URI).
143
144pls_index_profiles:profile_symbol(base, URI, Query, Range, Name, Detail, Kind) :-
145 get_document_item(URI, Range, defines(Predicate)),
146 Predicate = Name/_Arity,
147 term_string(Predicate, Detail),
148 atom_concat(Query,_,Name),
149 symbol_kind(function,Kind).
155index_declaration(URI, Pos, Directive, (Predicate, MorePredicates)) :-
156 argument_positions(Pos, [ArgPos, MoreArgsPos]),
157 index_declaration(URI, ArgPos, Directive, Predicate),
158 index_declaration(URI, MoreArgsPos, Directive, MorePredicates).
159
160index_declaration(URI, Pos, _Directive, Predicate) :-
161 argument_positions(Pos, [ArgPos]),
162 term_position_range(URI, ArgPos, Range),
163 pls_index:add_document_item(URI, Range, defines(Predicate)).
169index_exports(_URI, [], []).
170
171index_exports(URI, [Export | ExportRest], [ExportPos | ExportPosListRest]) :-
172 term_position_range(URI, ExportPos, Range),
173 pls_index:add_document_item(URI, Range, exports(Export)),
174 index_exports(URI, ExportRest, ExportPosListRest)