1 /**
2  * This file is part of DCD, a development tool for the D programming language.
3  * Copyright (C) 2014 Brian Schott
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 module dcd.server.autocomplete.doc;
20 
21 import std.algorithm;
22 import std.array;
23 import std.experimental.logger;
24 import std.typecons;
25 
26 import dcd.server.autocomplete.util;
27 
28 import dparse.lexer;
29 import dparse.rollback_allocator;
30 
31 import dsymbol.modulecache;
32 
33 import dcd.common.messages;
34 
35 /**
36  * Gets documentation for the symbol at the cursor
37  * Params:
38  *     request = the autocompletion request
39  * Returns:
40  *     the autocompletion response
41  */
42 public AutocompleteResponse getDoc(const AutocompleteRequest request,
43 	ref ModuleCache moduleCache)
44 {
45 //	trace("Getting doc comments");
46 	AutocompleteResponse response;
47 	RollbackAllocator rba;
48 	auto allocator = scoped!(ASTAllocator)();
49 	auto cache = StringCache(StringCache.defaultBucketCount);
50 	SymbolStuff stuff = getSymbolsForCompletion(request, CompletionType.ddoc,
51 		allocator, &rba, cache, moduleCache);
52 	if (stuff.symbols.length == 0)
53 		warning("Could not find symbol");
54 	else
55 	{
56 		bool isDitto(string s)
57 		{
58 			import std.uni : icmp;
59 			if (s.length > 5)
60 				return false;
61 			else
62 				return s.icmp("ditto") == 0;
63 		}
64 
65 		foreach(ref symbol; stuff.symbols.filter!(a => !a.doc.empty && !isDitto(a.doc)))
66 		{
67 			AutocompleteResponse.Completion c;
68 			c.documentation = symbol.doc;
69 			response.completions ~= c;
70 		}
71 	}
72 	return response;
73 }