More work on the dscanner / dcd split

This commit is contained in:
Hackerpilot 2013-07-17 00:01:54 -07:00
parent c83bb59a75
commit 6e5742167a
5 changed files with 82 additions and 69 deletions

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "msgpack-d"]
path = msgpack-d
url = https://github.com/msgpack/msgpack-d.git

View File

@ -317,7 +317,8 @@ local keywords = {
-- For this module to work the dscanner program must be installed. Configure the
-- path to the executable here
M.PATH_TO_DSCANNER = "/home/alaran/src/dscanner/dscanner"
M.PATH_TO_DSCANNER = "/home/brian/src/dscanner/dscanner"
M.PATH_TO_DCD_CLIENT = "/home/brian/src/dcd/dcd-client"
_M.textadept.editing.comment_string.dmd = '//'
_M.textadept.run.compile_command.dmd = 'dmd -c -o- %(filename)'
@ -341,7 +342,7 @@ local function showCompletionList(r)
buffer.auto_c_choose_single = false;
buffer.auto_c_max_width = 0
local completions = {}
for symbol, kind in r:gmatch("([@%w_]+) (%a)\n") do
for symbol, kind in r:gmatch("([@%w_]+)\t(%a)\n") do
completion = symbol
if kind == "k" then
completion = completion .. "?5"
@ -368,34 +369,25 @@ local function showCompletionList(r)
buffer.auto_c_choose_single = setting
end
--events.connect(events.CHAR_ADDED, function(ch)
-- if buffer:get_lexer() ~= "dmd" then return end
-- if ch > 255 then return end
-- local character = string.char(ch)
-- if character == "." or character == "(" then
-- local fileName = os.tmpname()
-- local tmpFile = io.open(fileName, "w")
-- tmpFile:write(buffer:get_text())
-- local command = M.PATH_TO_DSCANNER
-- .. (character == "." and " --dotComplete " or " --parenComplete ")
-- .. fileName .. " " .. buffer.current_pos .. " -I" .. buffer.filename:match(".+[\\/]")
-- local p = io.popen(command)
-- local r = p:read("*a")
-- if r ~= "\n" then
-- if character == "." then
-- showCompletionList(r)
-- elseif character == "(" then
-- if r:find("^completions\n") then
-- showCompletionList(r)
-- elseif r:find("^calltips\n.*") then
-- r = r:gsub("^calltips\n", "")
-- buffer:call_tip_show(buffer.current_pos, r:gsub("\\n", "\n"):gsub("\\t", "\t"):match("(.*)%s+$"))
-- end
-- end
-- end
-- os.remove(fileName)
-- end
--end)
events.connect(events.CHAR_ADDED, function(ch)
if buffer:get_lexer() ~= "dmd" then return end
if ch > 255 then return end
local character = string.char(ch)
if character == "." or character == "(" then
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 r = p:read("*a")
if r ~= "\n" then
showCompletionList(r)
end
os.remove(fileName)
end
end)
events.connect(events.FILE_AFTER_SAVE, function()
if buffer:get_lexer() ~= "dmd" then return end
@ -406,18 +398,20 @@ events.connect(events.FILE_AFTER_SAVE, function()
for line in p:lines() do
lineNumber, column, level, message = string.match(line, "^.-%((%d+):(%d+)%)%[(%w+)%]: (.+)$")
local l = tonumber(lineNumber) - 1
local c = tonumber(column)
if level == "error" then
buffer.annotation_style[l] = 8
else
buffer.annotation_style[l] = 2
end
local t = buffer.annotation_text[l]
if #t > 0 then
buffer.annotation_text[l] = buffer.annotation_text[l] .. "\n" .. message
else
buffer.annotation_text[l] = message
end
if l >= 0 then
local c = tonumber(column)
if level == "error" then
buffer.annotation_style[l] = 8
else
buffer.annotation_style[l] = 2
end
local t = buffer.annotation_text[l]
if #t > 0 then
buffer.annotation_text[l] = buffer.annotation_text[l] .. "\n" .. message
else
buffer.annotation_text[l] = message
end
end
end
end)

50
main.d
View File

@ -40,40 +40,40 @@ int main(string[] args)
getopt(args, "I", &importDirs, "sloc|l", &sloc,
"json|j", &json, "highlight", &highlight,
"ctags|c", &ctags, "recursive|r|R", &recursive, "help|h", &help,
"tokenCount", &tokenCount, "syntaxCheck", &syntaxCheck);
"tokenCount", &tokenCount, "syntaxCheck|s", &syntaxCheck);
}
catch (Exception e)
{
stderr.writeln(e.msg);
}
if (help)
{
printHelp(args[0]);
return 0;
}
if (help)
{
printHelp(args[0]);
return 0;
}
auto optionCount = count!"a"([sloc, highlight, ctags, json, tokenCount,
auto optionCount = count!"a"([sloc, highlight, ctags, json, tokenCount,
syntaxCheck]);
if (optionCount > 1)
{
stderr.writeln("Too many options specified");
return 1;
}
else if (optionCount < 1)
{
printHelp(args[0]);
return 1;
}
if (optionCount > 1)
{
stderr.writeln("Too many options specified");
return 1;
}
else if (optionCount < 1)
{
printHelp(args[0]);
return 1;
}
if (highlight)
if (highlight)
{
LexerConfig config;
config.iterStyle = IterationStyle.everything;
config.tokenStyle = TokenStyle.source;
File f = args.length == 1 ? stdin : File(args[1]);
ubyte[] buffer = uninitializedArray!(ubyte[])(f.size);
highlighter.highlight(byToken(f.rawRead(buffer), config),
File f = args.length == 1 ? stdin : File(args[1]);
ubyte[] buffer = uninitializedArray!(ubyte[])(f.size);
highlighter.highlight(byToken(f.rawRead(buffer), config),
args.length == 1 ? "stdin" : args[1]);
return 0;
}
@ -85,7 +85,6 @@ int main(string[] args)
config.fileName = usingStdin ? "stdin" : args[1];
File f = usingStdin ? stdin : File(args[1]);
auto bytes = usingStdin ? cast(ubyte[]) [] : uninitializedArray!(ubyte[])(f.size);
auto byteCount = f.size;
f.rawRead(bytes);
auto tokens = byToken(bytes, config);
@ -140,6 +139,10 @@ options:
well as any paths specified in /etc/dmd.conf. This is only used for the
--parenComplete and --dotComplete options.
--syntaxCheck | -s [sourceFile]
Lexes and parses sourceFile, printing the line and column number of any
syntax errors to stdout. One error or warning is printed per line.
--ctags | -c sourceFile
Generates ctags information from the given source code file. Note that
ctags information requires a filename, so stdin cannot be used in place
@ -147,6 +150,7 @@ options:
--recursive | -R | -r directory
When used with --ctags, dscanner will produce ctags output for all .d
and .di files contained within directory and its sub-directories.`,
and .di files contained within the given directory and its
sub-directories.`,
programName);
}

View File

@ -190,6 +190,13 @@ struct Token
if (startIndex > other.startIndex) return 1;
return 0;
}
int opCmp(size_t index) const nothrow pure
{
if (startIndex < index) return -1;
if (startIndex > index) return 1;
return 0;
}
}
/**

View File

@ -82,6 +82,9 @@ import std.string : format;
/**
* Params:
* tokens = the tokens parsed by std.d.lexer
* messageFunction = a function to call on error or warning messages.
* The parameters are the file name, line number, column number,
* and the error or warning message.
* Returns: the parsed module
*/
Module parseModule(const(Token)[] tokens, string fileName,
@ -4117,9 +4120,15 @@ q{(int a, ...)
if (currentIsOneOf(stringLiteral, wstringLiteral, dstringLiteral))
{
node.primary = advance();
bool alreadyWarned = false;
while (currentIsOneOf(stringLiteral, wstringLiteral,
dstringLiteral))
{
if (!alreadyWarned)
{
warn("Implicit concatenation of string literals");
alreadyWarned = true;
}
node.primary.value ~= advance().value;
}
}
@ -5913,7 +5922,9 @@ q{doStuff(5)}c;
string fileName;
/**
* Function that is called when a warning or error is encountered
* Function that is called when a warning or error is encountered.
* The parameters are the file name, line number, column number,
* and the error or warning message.
*/
void function(string, int, int, string) messageFunction;