Merge branch 'master' of https://github.com/Hackerpilot/DCD
This commit is contained in:
commit
7c2d21a40f
24
actypes.d
24
actypes.d
|
|
@ -533,29 +533,53 @@ static this()
|
||||||
auto void_ = allocate!ACSymbol(Mallocator.it, "void", CompletionKind.keyword);
|
auto void_ = allocate!ACSymbol(Mallocator.it, "void", CompletionKind.keyword);
|
||||||
|
|
||||||
builtinSymbols.insert(bool_);
|
builtinSymbols.insert(bool_);
|
||||||
|
bool_.type = bool_;
|
||||||
builtinSymbols.insert(int_);
|
builtinSymbols.insert(int_);
|
||||||
|
int_.type = int_;
|
||||||
builtinSymbols.insert(long_);
|
builtinSymbols.insert(long_);
|
||||||
|
long_.type = long_;
|
||||||
builtinSymbols.insert(byte_);
|
builtinSymbols.insert(byte_);
|
||||||
|
byte_.type = byte_;
|
||||||
builtinSymbols.insert(char_);
|
builtinSymbols.insert(char_);
|
||||||
|
char_.type = char_;
|
||||||
builtinSymbols.insert(dchar_);
|
builtinSymbols.insert(dchar_);
|
||||||
|
dchar_.type = dchar_;
|
||||||
builtinSymbols.insert(short_);
|
builtinSymbols.insert(short_);
|
||||||
|
short_.type = short_;
|
||||||
builtinSymbols.insert(ubyte_);
|
builtinSymbols.insert(ubyte_);
|
||||||
|
ubyte_.type = ubyte_;
|
||||||
builtinSymbols.insert(uint_);
|
builtinSymbols.insert(uint_);
|
||||||
|
uint_.type = uint_;
|
||||||
builtinSymbols.insert(ulong_);
|
builtinSymbols.insert(ulong_);
|
||||||
|
ulong_.type = ulong_;
|
||||||
builtinSymbols.insert(ushort_);
|
builtinSymbols.insert(ushort_);
|
||||||
|
ushort_.type = ushort_;
|
||||||
builtinSymbols.insert(wchar_);
|
builtinSymbols.insert(wchar_);
|
||||||
|
wchar_.type = wchar_;
|
||||||
builtinSymbols.insert(cdouble_);
|
builtinSymbols.insert(cdouble_);
|
||||||
|
cdouble_.type = cdouble_;
|
||||||
builtinSymbols.insert(cent_);
|
builtinSymbols.insert(cent_);
|
||||||
|
cent_.type = cent_;
|
||||||
builtinSymbols.insert(cfloat_);
|
builtinSymbols.insert(cfloat_);
|
||||||
|
cfloat_.type = cfloat_;
|
||||||
builtinSymbols.insert(creal_);
|
builtinSymbols.insert(creal_);
|
||||||
|
creal_.type = creal_;
|
||||||
builtinSymbols.insert(double_);
|
builtinSymbols.insert(double_);
|
||||||
|
double_.type = double_;
|
||||||
builtinSymbols.insert(float_);
|
builtinSymbols.insert(float_);
|
||||||
|
float_.type = float_;
|
||||||
builtinSymbols.insert(idouble_);
|
builtinSymbols.insert(idouble_);
|
||||||
|
idouble_.type = idouble_;
|
||||||
builtinSymbols.insert(ifloat_);
|
builtinSymbols.insert(ifloat_);
|
||||||
|
ifloat_.type = ifloat_;
|
||||||
builtinSymbols.insert(ireal_);
|
builtinSymbols.insert(ireal_);
|
||||||
|
ireal_.type = ireal_;
|
||||||
builtinSymbols.insert(real_);
|
builtinSymbols.insert(real_);
|
||||||
|
real_.type = real_;
|
||||||
builtinSymbols.insert(ucent_);
|
builtinSymbols.insert(ucent_);
|
||||||
|
ucent_.type = ucent_;
|
||||||
builtinSymbols.insert(void_);
|
builtinSymbols.insert(void_);
|
||||||
|
void_.type = void_;
|
||||||
|
|
||||||
// writeln(">>Builtin symbols");
|
// writeln(">>Builtin symbols");
|
||||||
// foreach (symbol; builtinSymbols[])
|
// foreach (symbol; builtinSymbols[])
|
||||||
|
|
|
||||||
|
|
@ -571,7 +571,6 @@ T getExpression(T)(T beforeTokens)
|
||||||
size_t i = beforeTokens.length - 1;
|
size_t i = beforeTokens.length - 1;
|
||||||
IdType open;
|
IdType open;
|
||||||
IdType close;
|
IdType close;
|
||||||
bool hasSpecialPrefix = false;
|
|
||||||
expressionLoop: while (true)
|
expressionLoop: while (true)
|
||||||
{
|
{
|
||||||
switch (beforeTokens[i].type)
|
switch (beforeTokens[i].type)
|
||||||
|
|
@ -603,15 +602,9 @@ T getExpression(T)(T beforeTokens)
|
||||||
case tok!"creal":
|
case tok!"creal":
|
||||||
case tok!"this":
|
case tok!"this":
|
||||||
case tok!"identifier":
|
case tok!"identifier":
|
||||||
if (hasSpecialPrefix)
|
|
||||||
i++;
|
|
||||||
break;
|
break;
|
||||||
case tok!".":
|
case tok!".":
|
||||||
break;
|
break;
|
||||||
case tok!"*":
|
|
||||||
case tok!"&":
|
|
||||||
hasSpecialPrefix = true;
|
|
||||||
break;
|
|
||||||
case tok!")":
|
case tok!")":
|
||||||
open = tok!")";
|
open = tok!")";
|
||||||
close = tok!"(";
|
close = tok!"(";
|
||||||
|
|
@ -653,8 +646,6 @@ T getExpression(T)(T beforeTokens)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (hasSpecialPrefix)
|
|
||||||
i++;
|
|
||||||
i++;
|
i++;
|
||||||
break expressionLoop;
|
break expressionLoop;
|
||||||
}
|
}
|
||||||
|
|
@ -676,15 +667,15 @@ void setImportCompletions(T)(T tokens, ref AutocompleteResponse response)
|
||||||
{
|
{
|
||||||
response.completionType = CompletionType.identifiers;
|
response.completionType = CompletionType.identifiers;
|
||||||
auto moduleParts = tokens.filter!(a => a.type == tok!"identifier").map!("a.text").array();
|
auto moduleParts = tokens.filter!(a => a.type == tok!"identifier").map!("a.text").array();
|
||||||
if (moduleParts.length == 0)
|
|
||||||
return;
|
|
||||||
string path = buildPath(moduleParts);
|
string path = buildPath(moduleParts);
|
||||||
|
|
||||||
foreach (importDirectory; ModuleCache.getImportPaths())
|
foreach (importDirectory; ModuleCache.getImportPaths())
|
||||||
{
|
{
|
||||||
string p = buildPath(importDirectory, path);
|
string p = buildPath(importDirectory, path);
|
||||||
Log.trace("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))
|
||||||
{
|
{
|
||||||
if (isFile(name) && (name.endsWith(".d") || name.endsWith(".di")))
|
if (isFile(name) && (name.endsWith(".d") || name.endsWith(".di")))
|
||||||
|
|
|
||||||
22
client.d
22
client.d
|
|
@ -57,6 +57,8 @@ int main(string[] args)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AutocompleteRequest request;
|
||||||
|
|
||||||
if (help)
|
if (help)
|
||||||
{
|
{
|
||||||
printHelp(args[0]);
|
printHelp(args[0]);
|
||||||
|
|
@ -64,7 +66,6 @@ int main(string[] args)
|
||||||
}
|
}
|
||||||
else if (shutdown || clearCache)
|
else if (shutdown || clearCache)
|
||||||
{
|
{
|
||||||
AutocompleteRequest request;
|
|
||||||
if (shutdown)
|
if (shutdown)
|
||||||
request.kind = RequestKind.shutdown;
|
request.kind = RequestKind.shutdown;
|
||||||
else if (clearCache)
|
else if (clearCache)
|
||||||
|
|
@ -75,12 +76,16 @@ int main(string[] args)
|
||||||
}
|
}
|
||||||
else if (importPaths.length > 0)
|
else if (importPaths.length > 0)
|
||||||
{
|
{
|
||||||
AutocompleteRequest request;
|
request.kind |= RequestKind.addImport;
|
||||||
request.kind = RequestKind.addImport;
|
|
||||||
request.importPaths = importPaths.map!(a => absolutePath(a)).array;
|
request.importPaths = importPaths.map!(a => absolutePath(a)).array;
|
||||||
|
if (cursorPos == size_t.max)
|
||||||
|
{
|
||||||
TcpSocket socket = createSocket(port);
|
TcpSocket socket = createSocket(port);
|
||||||
scope (exit) { socket.shutdown(SocketShutdown.BOTH); socket.close(); }
|
scope (exit) { socket.shutdown(SocketShutdown.BOTH); socket.close(); }
|
||||||
return sendRequest(socket, request) ? 0 : 1;
|
if (!sendRequest(socket, request))
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (cursorPos == size_t.max)
|
else if (cursorPos == size_t.max)
|
||||||
{
|
{
|
||||||
|
|
@ -116,18 +121,17 @@ int main(string[] args)
|
||||||
f.rawRead(sourceCode);
|
f.rawRead(sourceCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create message
|
|
||||||
AutocompleteRequest request;
|
|
||||||
request.fileName = fileName;
|
request.fileName = fileName;
|
||||||
request.importPaths = importPaths;
|
request.importPaths = importPaths;
|
||||||
request.sourceCode = sourceCode;
|
request.sourceCode = sourceCode;
|
||||||
request.cursorPosition = cursorPos;
|
request.cursorPosition = cursorPos;
|
||||||
|
|
||||||
if (symbolLocation)
|
if (symbolLocation)
|
||||||
request.kind = RequestKind.symbolLocation;
|
request.kind |= RequestKind.symbolLocation;
|
||||||
else if (doc)
|
else if (doc)
|
||||||
request.kind = RequestKind.doc;
|
request.kind |= RequestKind.doc;
|
||||||
else
|
else
|
||||||
request.kind = RequestKind.autocomplete;
|
request.kind |= RequestKind.autocomplete;
|
||||||
|
|
||||||
// Send message to server
|
// Send message to server
|
||||||
TcpSocket socket = createSocket(port);
|
TcpSocket socket = createSocket(port);
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ public:
|
||||||
|
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
|
rootSymbol.acSymbol.parts.insert(builtinSymbols[]);
|
||||||
assignToScopes(rootSymbol.acSymbol);
|
assignToScopes(rootSymbol.acSymbol);
|
||||||
resolveImports(moduleScope);
|
resolveImports(moduleScope);
|
||||||
}
|
}
|
||||||
|
|
@ -62,7 +63,7 @@ private:
|
||||||
s.symbols.insert(currentSymbol);
|
s.symbols.insert(currentSymbol);
|
||||||
foreach (part; currentSymbol.parts[])
|
foreach (part; currentSymbol.parts[])
|
||||||
{
|
{
|
||||||
std.utf.validate(part.name);
|
if (part.kind != CompletionKind.keyword)
|
||||||
assignToScopes(part);
|
assignToScopes(part);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -149,9 +149,8 @@ private:
|
||||||
else if (t.type2.symbol !is null)
|
else if (t.type2.symbol !is null)
|
||||||
{
|
{
|
||||||
// TODO: global scoped symbol handling
|
// TODO: global scoped symbol handling
|
||||||
string[] symbolParts = cast(string[]) Mallocator.it.allocate(
|
size_t l = t.type2.symbol.identifierOrTemplateChain.identifiersOrTemplateInstances.length;
|
||||||
t.type2.symbol.identifierOrTemplateChain.identifiersOrTemplateInstances.length
|
string[] symbolParts = (cast(string*) Mallocator.it.allocate(l * string.sizeof))[0 .. l];
|
||||||
* string.sizeof);
|
|
||||||
scope(exit) Mallocator.it.deallocate(symbolParts);
|
scope(exit) Mallocator.it.deallocate(symbolParts);
|
||||||
expandSymbol(symbolParts, t.type2.symbol.identifierOrTemplateChain);
|
expandSymbol(symbolParts, t.type2.symbol.identifierOrTemplateChain);
|
||||||
auto symbols = moduleScope.getSymbolsByNameAndCursor(
|
auto symbols = moduleScope.getSymbolsByNameAndCursor(
|
||||||
|
|
@ -179,7 +178,10 @@ private:
|
||||||
{
|
{
|
||||||
auto identOrTemplate = chain.identifiersOrTemplateInstances[i];
|
auto identOrTemplate = chain.identifiersOrTemplateInstances[i];
|
||||||
if (identOrTemplate is null)
|
if (identOrTemplate is null)
|
||||||
|
{
|
||||||
|
strings[i] = null;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
strings[i] = internString(identOrTemplate.templateInstance is null ?
|
strings[i] = internString(identOrTemplate.templateInstance is null ?
|
||||||
identOrTemplate.identifier.text
|
identOrTemplate.identifier.text
|
||||||
: identOrTemplate.templateInstance.identifier.text);
|
: identOrTemplate.templateInstance.identifier.text);
|
||||||
|
|
|
||||||
2
dscanner
2
dscanner
|
|
@ -1 +1 @@
|
||||||
Subproject commit 25f0d93b90cf039577ed2fb7091efd18770dc06c
|
Subproject commit f54f7823dc62c14b7afb6b7db6e7693e79be34fa
|
||||||
13
messages.d
13
messages.d
|
|
@ -111,18 +111,19 @@ enum CompletionType : string
|
||||||
*/
|
*/
|
||||||
enum RequestKind : ubyte
|
enum RequestKind : ubyte
|
||||||
{
|
{
|
||||||
|
uninitialized = 0b00000000,
|
||||||
/// Autocompletion
|
/// Autocompletion
|
||||||
autocomplete,
|
autocomplete = 0b00000001,
|
||||||
/// Clear the completion cache
|
/// Clear the completion cache
|
||||||
clearCache,
|
clearCache = 0b00000010,
|
||||||
/// Add import directory to server
|
/// Add import directory to server
|
||||||
addImport,
|
addImport = 0b00000100,
|
||||||
/// Shut down the server
|
/// Shut down the server
|
||||||
shutdown,
|
shutdown = 0b00001000,
|
||||||
/// Get declaration location of given symbol
|
/// Get declaration location of given symbol
|
||||||
symbolLocation,
|
symbolLocation = 0b00010000,
|
||||||
/// Get the doc comments for the symbol
|
/// Get the doc comments for the symbol
|
||||||
doc
|
doc = 0b00100000,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,10 @@ struct ModuleCache
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
import std.typecons;
|
import std.typecons;
|
||||||
File f = File(cachedLocation);
|
File f = File(cachedLocation);
|
||||||
ubyte[] source = cast(ubyte[]) Mallocator.it.allocate(cast(size_t)f.size);
|
immutable fileSize = cast(size_t)f.size;
|
||||||
|
if (fileSize == 0)
|
||||||
|
return symbols;
|
||||||
|
ubyte[] source = cast(ubyte[]) Mallocator.it.allocate(fileSize);
|
||||||
f.rawRead(source);
|
f.rawRead(source);
|
||||||
LexerConfig config;
|
LexerConfig config;
|
||||||
config.fileName = cachedLocation;
|
config.fileName = cachedLocation;
|
||||||
|
|
|
||||||
41
server.d
41
server.d
|
|
@ -145,32 +145,28 @@ int main(string[] args)
|
||||||
|
|
||||||
AutocompleteRequest request;
|
AutocompleteRequest request;
|
||||||
msgpack.unpack(buffer[size_t.sizeof .. bytesReceived], request);
|
msgpack.unpack(buffer[size_t.sizeof .. bytesReceived], request);
|
||||||
final switch (request.kind)
|
if (request.kind & RequestKind.clearCache)
|
||||||
{
|
{
|
||||||
case RequestKind.addImport:
|
|
||||||
ModuleCache.addImportPaths(request.importPaths);
|
|
||||||
break;
|
|
||||||
case RequestKind.clearCache:
|
|
||||||
Log.info("Clearing cache.");
|
Log.info("Clearing cache.");
|
||||||
ModuleCache.clear();
|
ModuleCache.clear();
|
||||||
break;
|
}
|
||||||
case RequestKind.shutdown:
|
else if (request.kind & RequestKind.shutdown)
|
||||||
|
{
|
||||||
Log.info("Shutting down.");
|
Log.info("Shutting down.");
|
||||||
break serverLoop;
|
break serverLoop;
|
||||||
case RequestKind.autocomplete:
|
}
|
||||||
// try
|
if (request.kind & RequestKind.addImport)
|
||||||
// {
|
ModuleCache.addImportPaths(request.importPaths);
|
||||||
|
else if (request.kind & RequestKind.autocomplete)
|
||||||
|
{
|
||||||
|
Log.info("Getting completions");
|
||||||
AutocompleteResponse response = complete(request);
|
AutocompleteResponse response = complete(request);
|
||||||
ubyte[] responseBytes = msgpack.pack(response);
|
ubyte[] responseBytes = msgpack.pack(response);
|
||||||
s.send(responseBytes);
|
s.send(responseBytes);
|
||||||
// }
|
}
|
||||||
// catch (Exception e)
|
else if (request.kind & RequestKind.doc)
|
||||||
// {
|
{
|
||||||
// Log.error("Could not handle autocomplete request due to an exception:",
|
Log.info("Getting doc comment");
|
||||||
// e.msg);
|
|
||||||
// }
|
|
||||||
break;
|
|
||||||
case RequestKind.doc:
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
AutocompleteResponse response = getDoc(request);
|
AutocompleteResponse response = getDoc(request);
|
||||||
|
|
@ -181,9 +177,9 @@ int main(string[] args)
|
||||||
{
|
{
|
||||||
Log.error("Could not get DDoc information", e.msg);
|
Log.error("Could not get DDoc information", e.msg);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
else if (request.kind & RequestKind.symbolLocation)
|
||||||
case RequestKind.symbolLocation:
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
AutocompleteResponse response = findDeclaration(request);
|
AutocompleteResponse response = findDeclaration(request);
|
||||||
|
|
@ -194,8 +190,9 @@ int main(string[] args)
|
||||||
{
|
{
|
||||||
Log.error("Could not get symbol location", e.msg);
|
Log.error("Could not get symbol location", e.msg);
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
Log.error("Unknown request type");
|
||||||
Log.info("Request processed in ", requestWatch.peek().to!("msecs", float), " milliseconds");
|
Log.info("Request processed in ", requestWatch.peek().to!("msecs", float), " milliseconds");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
module string_interning;
|
module string_interning;
|
||||||
|
|
||||||
import std.lexer;
|
import std.d.lexer;
|
||||||
|
|
||||||
string internString(string s)
|
string internString(string s)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue