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