Implemented stdin feature

This commit is contained in:
Hackerpilot 2013-08-09 17:32:43 +00:00
parent e3fba24b7d
commit b4b47eacfd
3 changed files with 22 additions and 8 deletions

View File

@ -47,7 +47,8 @@ AutocompleteResponse complete(AutocompleteRequest request, string[] importPaths)
auto sortedTokens = assumeSorted(tokenArray);
auto beforeTokens = sortedTokens.lowerBound(cast(size_t) request.cursorPosition);
if (beforeTokens[$ - 1] == TokenType.lParen && beforeTokens.length >= 2)
if (beforeTokens.length >= 2 && beforeTokens[$ - 1] == TokenType.lParen)
{
immutable(string)[] completions;
switch (beforeTokens[$ - 2].type)
@ -87,7 +88,7 @@ AutocompleteResponse complete(AutocompleteRequest request, string[] importPaths)
break;
}
}
else if (beforeTokens[$ - 1] == TokenType.dot && beforeTokens.length >= 2)
else if (beforeTokens.length >= 2 && beforeTokens[$ - 1] == TokenType.dot)
{
switch (beforeTokens[$ - 2].type)
{

View File

@ -83,8 +83,23 @@ int main(string[] args)
bool usingStdin = args.length <= 1;
string fileName = usingStdin ? "stdin" : args[1];
File f = usingStdin ? stdin : File(args[1]);
ubyte[] sourceCode = usingStdin ? cast(ubyte[]) [] : uninitializedArray!(ubyte[])(f.size);
f.rawRead(sourceCode);
ubyte[] sourceCode;
if (usingStdin)
{
ubyte[4096] buf;
while (true)
{
auto b = f.rawRead(buf);
if (b.length == 0)
break;
sourceCode ~= b;
}
}
else
{
sourceCode = uninitializedArray!(ubyte[])(f.size);
f.rawRead(sourceCode);
}
// Create message
AutocompleteRequest request;

View File

@ -72,10 +72,8 @@ function M.autocomplete(ch)
local fileName = os.tmpname()
local tmpFile = io.open(fileName, "w")
tmpFile:write(buffer:get_text())
local command = M.PATH_TO_DCD_CLIENT .. " -c" .. buffer.current_pos
.. " " .. fileName
print(command)
local p = io.popen(command)
local command = M.PATH_TO_DCD_CLIENT .. " -c" .. buffer.current_pos .. " " .. fileName
local p = io.popen(command, "r")
local r = p:read("*a")
print(r)
if r ~= "\n" then