This commit is contained in:
parent
bb3b33b471
commit
1d807075fd
|
@ -42,8 +42,9 @@ import stupidlog;
|
|||
|
||||
AutocompleteResponse findDeclaration(const AutocompleteRequest request)
|
||||
{
|
||||
AutocompleteResponse response;
|
||||
LexerConfig config;
|
||||
Log.info("Finding declaration");
|
||||
AutocompleteResponse response;
|
||||
LexerConfig config;
|
||||
config.fileName = "stdin";
|
||||
auto tokens = byToken(cast(ubyte[]) request.sourceCode, config);
|
||||
const(Token)[] tokenArray = void;
|
||||
|
@ -58,31 +59,33 @@ AutocompleteResponse findDeclaration(const AutocompleteRequest request)
|
|||
|
||||
auto beforeTokens = sortedTokens.lowerBound(cast(size_t) request.cursorPosition);
|
||||
|
||||
Log.info("Token at cursor: ", beforeTokens[$ - 1]);
|
||||
Log.info("Token at cursor: ", beforeTokens[$ - 1]);
|
||||
|
||||
const(Scope)* completionScope = generateAutocompleteTrees(tokenArray, "stdin");
|
||||
auto expression = getExpression(beforeTokens);
|
||||
const(Scope)* completionScope = generateAutocompleteTrees(tokenArray, "stdin");
|
||||
auto expression = getExpression(beforeTokens);
|
||||
|
||||
writeln(expression);
|
||||
const(ACSymbol)*[] symbols = getSymbolsByTokenChain(completionScope, expression,
|
||||
request.cursorPosition, CompletionType.identifiers);
|
||||
|
||||
const(ACSymbol)*[] symbols = getSymbolsByTokenChain(completionScope, expression,
|
||||
request.cursorPosition, CompletionType.identifiers);
|
||||
if (symbols.length > 0)
|
||||
{
|
||||
response.symbolLocation = symbols[0].location;
|
||||
response.symbolFilePath = symbols[0].symbolFile;
|
||||
Log.info(beforeTokens[$ - 1].value, " declared in ",
|
||||
response.symbolFilePath, " at ", response.symbolLocation);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.error("Could not find symbol");
|
||||
}
|
||||
|
||||
if (symbols.length > 0)
|
||||
{
|
||||
response.symbolLocation = symbols[0].location;
|
||||
response.symbolFilePath = symbols[0].symbolFile;
|
||||
Log.info(beforeTokens[$ - 1].value, " declared in ",
|
||||
response.symbolFilePath, " at ", response.symbolLocation);
|
||||
}
|
||||
|
||||
return response;
|
||||
return response;
|
||||
}
|
||||
|
||||
const(ACSymbol)*[] getSymbolsByTokenChain(T)(const(Scope)* completionScope,
|
||||
T tokens, size_t cursorPosition, CompletionType completionType)
|
||||
T tokens, size_t cursorPosition, CompletionType completionType)
|
||||
{
|
||||
// Find the symbol corresponding to the beginning of the chain
|
||||
// Find the symbol corresponding to the beginning of the chain
|
||||
const(ACSymbol)*[] symbols = completionScope.getSymbolsByNameAndCursor(
|
||||
tokens[0].value, cursorPosition);
|
||||
if (symbols.length == 0)
|
||||
|
@ -227,7 +230,7 @@ const(ACSymbol)*[] getSymbolsByTokenChain(T)(const(Scope)* completionScope,
|
|||
break loop;
|
||||
}
|
||||
}
|
||||
return symbols;
|
||||
return symbols;
|
||||
}
|
||||
|
||||
AutocompleteResponse complete(const AutocompleteRequest request)
|
||||
|
@ -392,11 +395,11 @@ void setCompletions(T)(ref AutocompleteResponse response,
|
|||
if (tokens.length == 0)
|
||||
return;
|
||||
|
||||
const(ACSymbol)*[] symbols = getSymbolsByTokenChain(completionScope, tokens,
|
||||
cursorPosition, completionType);
|
||||
const(ACSymbol)*[] symbols = getSymbolsByTokenChain(completionScope, tokens,
|
||||
cursorPosition, completionType);
|
||||
|
||||
if (symbols.length == 0)
|
||||
return;
|
||||
if (symbols.length == 0)
|
||||
return;
|
||||
|
||||
if (completionType == CompletionType.identifiers)
|
||||
{
|
||||
|
@ -554,7 +557,7 @@ void setImportCompletions(T)(T tokens, ref AutocompleteResponse response)
|
|||
foreach (importDirectory; ModuleCache.getImportPaths())
|
||||
{
|
||||
string p = format("%s%s%s", importDirectory, dirSeparator, path);
|
||||
writeln("Checking for ", p);
|
||||
Log.trace("Checking for ", p);
|
||||
if (!exists(p))
|
||||
continue;
|
||||
foreach (string name; dirEntries(p, SpanMode.shallow))
|
||||
|
|
17
client.d
17
client.d
|
@ -119,7 +119,7 @@ int main(string[] args)
|
|||
request.importPaths = importPaths;
|
||||
request.sourceCode = sourceCode;
|
||||
request.cursorPosition = cursorPos;
|
||||
request.kind = symbolLocation ? RequestKind.symbolLocation : RequestKind.autocomplete;
|
||||
request.kind = symbolLocation ? RequestKind.symbolLocation : RequestKind.autocomplete;
|
||||
|
||||
// Send message to server
|
||||
TcpSocket socket = createSocket(port);
|
||||
|
@ -129,10 +129,10 @@ int main(string[] args)
|
|||
|
||||
AutocompleteResponse response = getResponse(socket);
|
||||
|
||||
if (symbolLocation)
|
||||
printLocationResponse(response);
|
||||
else
|
||||
printCompletionResponse(response);
|
||||
if (symbolLocation)
|
||||
printLocationResponse(response);
|
||||
else
|
||||
printCompletionResponse(response);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -214,12 +214,15 @@ AutocompleteResponse getResponse(TcpSocket socket)
|
|||
|
||||
void printLocationResponse(AutocompleteResponse response)
|
||||
{
|
||||
writefln("%s\t%d", response.symbolFilePath, response.symbolLocation);
|
||||
if (response.symbolFilePath is null)
|
||||
writeln("Not found");
|
||||
else
|
||||
writefln("%s\t%d", response.symbolFilePath, response.symbolLocation);
|
||||
}
|
||||
|
||||
void printCompletionResponse(AutocompleteResponse response)
|
||||
{
|
||||
if (response.completions.length > 0)
|
||||
if (response.completions.length > 0)
|
||||
{
|
||||
writeln(response.completionType);
|
||||
auto app = appender!(string[])();
|
||||
|
|
|
@ -113,8 +113,15 @@ function M.gotoDeclaration()
|
|||
p:close()
|
||||
local tmpFile = io.open(fileName, "r")
|
||||
local r = tmpFile:read("*a")
|
||||
if r ~= "\n" then
|
||||
-- TODO: Go to declaration
|
||||
if r ~= "Not found\n" then
|
||||
path, position = r:match("^(.-)\t(%d+)")
|
||||
if (path ~= nil and position ~= nil) then
|
||||
if (path ~= "stdin") then
|
||||
io.open_file(path)
|
||||
end
|
||||
buffer:goto_pos(tonumber(position))
|
||||
buffer:word_right_end_extend()
|
||||
end
|
||||
end
|
||||
os.remove(fileName)
|
||||
end
|
||||
|
|
|
@ -31,6 +31,7 @@ keys.dmd = {
|
|||
(_USERHOME..'/modules/dmd/init.lua'):iconv('UTF-8', _CHARSET) },
|
||||
},
|
||||
['c\n'] = {autocomplete},
|
||||
['cG'] = {_M.dcd.gotoDeclaration},
|
||||
['down'] = {_M.dcd.cycleCalltips, 1},
|
||||
['up'] = {_M.dcd.cycleCalltips, -1},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue