Fix #67 and update DScanner

This commit is contained in:
Hackerpilot 2013-11-04 16:21:33 -08:00
parent ed7a667ae4
commit 52b919bd3a
4 changed files with 45 additions and 33 deletions

View File

@ -428,16 +428,6 @@ private:
return "%s %s%s".format(formatNode(returnType), name, parameterString);
}
static string formatNode(T)(T node)
{
if (node is null) return "";
import formatter;
auto app = appender!(char[])();
auto f = new Formatter!(typeof(app))(app);
f.format(node);
return to!string(app.data);
}
/// Current protection type
TokenType protection;
@ -499,13 +489,13 @@ private:
{
foreach (importInfo; currentScope.importInformation)
{
auto symbols = ModuleCache.getSymbolsInModule(importInfo.modulePath);
auto symbols = ModuleCache.getSymbolsInModule(
ModuleCache.resolveImportLoctation(importInfo.modulePath));
if (importInfo.importedSymbols.length == 0)
{
currentScope.symbols ~= symbols;
if (importInfo.isPublic && currentScope.parent is null)
{
Log.trace("Public import");
rootSymbol.acSymbol.parts ~= symbols;
}
continue;
@ -708,8 +698,11 @@ private:
}
if (suffix.parameters)
{
Log.error("TODO: Function type suffix");
return null;
ACSymbol* s = new ACSymbol;
s.type = symbol;
s.qualifier = SymbolQualifier.func;
s.callTip = suffix.delegateOrFunction.value ~ formatNode(suffix.parameters);
return s;
}
return null;
}
@ -836,7 +829,7 @@ string[] iotcToStringArray(const IdentifierOrTemplateChain iotc)
private static string convertChainToImportPath(IdentifierChain chain)
{
return to!string(chain.identifiers.map!(a => a.value).join(dirSeparator).array) ~ ".d";
return to!string(chain.identifiers.map!(a => a.value).join(dirSeparator).array);
}
version(unittest) Module parseTestCode(string code)
@ -852,4 +845,14 @@ version(unittest) Module parseTestCode(string code)
return m;
}
string formatNode(T)(T node)
{
if (node is null) return "";
import formatter;
auto app = appender!(char[])();
auto f = new Formatter!(typeof(app))(app);
f.format(node);
return to!string(app.data);
}
private void doesNothing(string a, int b, int c, string d) {}

View File

@ -570,7 +570,9 @@ void setImportCompletions(T)(T tokens, ref AutocompleteResponse response)
else if (isDir(name))
{
response.completions ~= name.baseName();
response.completionKinds ~= CompletionKind.packageName;
response.completionKinds ~=
exists(buildPath(name, "package.d")) || exists(buildPath(name, "package.di"))
? CompletionKind.packageName : CompletionKind.moduleName;
}
}
}

@ -1 +1 @@
Subproject commit e3819643bbec121e16abda6f980cc096d2e7f4f1
Subproject commit c522170983576c533b8a378040648612aeee7953

View File

@ -97,14 +97,12 @@ struct ModuleCache
/**
* Params:
* moduleName = the name of the module in "a/b.d" form
* moduleName = the name of the module in "a/b/c" form
* Returns:
* The symbols defined in the given module
*/
static const(ACSymbol)*[] getSymbolsInModule(string moduleName)
static const(ACSymbol)*[] getSymbolsInModule(string location)
{
string location = resolveImportLoctation(moduleName);
if (location is null)
return [];
@ -115,7 +113,7 @@ struct ModuleCache
return [];
}
Log.info("Getting symbols for module ", moduleName);
Log.info("Getting symbols for ", location);
recursionGuard[location] = true;
@ -154,28 +152,37 @@ struct ModuleCache
/**
* Params:
* moduleName the name of the module being imported, in "a/b/c.d" style
* moduleName the name of the module being imported, in "a/b/c" style
* Returns:
* The absolute path to the file that contains the module, or null if
* not found.
*/
static string resolveImportLoctation(string moduleName)
{
// Log.trace("Resolving location of ", moduleName);
if (isRooted(moduleName))
return moduleName;
string[] alternatives;
foreach (path; importPaths)
{
string filePath = path ~ "/" ~ moduleName;
if (filePath.exists())
return filePath;
filePath ~= "i"; // check for x.di if x.d isn't found
if (filePath.exists())
return filePath;
string filePath = buildPath(path, moduleName);
if (exists(filePath ~ ".d") && isFile(filePath ~ ".d"))
alternatives = (filePath ~ ".d") ~ alternatives;
else if (exists(filePath ~ ".di") && isFile(filePath ~ ".di"))
alternatives = (filePath ~ ".di") ~ alternatives;
else if (exists(filePath) && isDir(filePath))
{
string packagePath = buildPath(filePath, "package.d");
if (exists(packagePath) && isFile(packagePath))
{
alternatives ~= packagePath;
continue;
}
packagePath ~= "i";
if (exists(packagePath) && isFile(packagePath))
alternatives ~= packagePath;
}
}
Log.error("Could not find ", moduleName);
return null;
return alternatives.length > 0 ? alternatives[0] : null;
}
static const(string[]) getImportPaths()