www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - The best way to write IDE helper tool

reply unDEFER <undefer gmail.com> writes:
Hello!
I know there is IDE tools like DCD, but I don't like it because 
it hasn't UCFS-suggestions.
So I have written my own patches to DMD to decide this problem. 
The patches adds the "-interp" option to compiler. In this mode 
the compiler is interrupted after semantic3 stage and displays 
the next prompt:

INTERPRETER MODE

Write here short commands like:
<modulename>:line - as the first line to setup scope of the 
command
pragma(msg, "message");
templatename!(args)();
<empty line> - to start interpreter
exit - to finish interpreter mode

Also the patches adds 2 traits "isUFCSCallable" and 
"locationOfDeclaration".
All is good, my text editor calls after changes the modified dmd 
and writes to it's stdin short programs like this:

import std.algorithm.searching: startsWith;
static if (__traits(compiles, rhs.stringof.startsWith("module ")) 
&&
     rhs.stringof.startsWith("module "))
     allMembersOfModule!("rhs");
else static if (__traits(compiles, isType!(rhs)) && isType!(rhs))
     allMembersOfType!(rhs, "aliasthis");
else static if (__traits(compiles, typeof(rhs)))
     allMembersOfType!(typeof(rhs), "aliasthis");
else static if (__traits(compiles, typeof(rhs())))
     allMembersOfType!(typeof(rhs()), "aliasthis");
else pragma(msg, "Can't find type of expression");

To find what to suggest after a user writes "rhs.". 
allMembersOfModule and allMembersOfType declared in my 
autocompletion_routines module and inserts in each module by 
other new option of the modified compiler "-importtoall=".

So the problem of this approach is that the parsing of whole 
project is performed after EVERY edit of code.
What I want is to make "interp" mode better and add command to 
insert/remove lines to it's AST.
I see that I need to add to AST also fields like "dependencies" 
("using") to each declaration.. But seems there will problems 
with approach which uses the compiler. It rewrites "foreach" as 
"for" if it not in template and so on.. Don't sure that after 
this changes will be possible easy change lines in AST.

libdparse also doesn't work for me. It doesn't do CTFE so limits 
to UCFS suggestion like "isRange" will not work.

How you see what the best existing tools can help me finish this 
task?
Dec 20 2018
next sibling parent reply nateliv <natelivliv outlook.fr> writes:
Write them to the actual models, using the write flag (or should 
suggest that by default?)
Dec 20 2018
parent unDEFER <undefer gmail.com> writes:
On Thursday, 20 December 2018 at 17:14:33 UTC, nateliv wrote:
 Write them to the actual models, using the write flag (or 
 should suggest that by default?)
Sorry, I don't understand. What is them? Autocompletion suggestions, patches or changes to AST? What is actual models? Models of what? And which write flag?
Dec 20 2018
prev sibling parent reply Andre Pany <andre s-e-a-p.de> writes:
On Thursday, 20 December 2018 at 14:17:11 UTC, unDEFER wrote:
 Hello!
 I know there is IDE tools like DCD, but I don't like it because 
 it hasn't UCFS-suggestions.
 So I have written my own patches to DMD to decide this problem. 
 The patches adds the "-interp" option to compiler. In this mode 
 the compiler is interrupted after semantic3 stage and displays 
 the next prompt:

 [...]
Without knowing the details I assume dcd is using libdparse and here some features are missing. If we could add the missing features to libdparse, dcd and also other tools would immediately profit (dscanner, dfrmt,...) Kind regards Andre
Dec 20 2018
next sibling parent unDEFER <undefer gmail.com> writes:
On Thursday, 20 December 2018 at 18:21:55 UTC, Andre Pany wrote:

 Without knowing the details I assume dcd is using libdparse and 
 here some features are missing.
 If we could add the missing features to libdparse, dcd and also 
 other tools would immediately profit (dscanner, dfrmt,...)

 Kind regards
 Andre
Easy to say "add the missing features to libdparse" :-) It means write CTFE-able parser. So I have taken the ready compiler for this task.
Dec 20 2018
prev sibling parent Basile B. <b2.temp gmx.com> writes:
On Thursday, 20 December 2018 at 18:21:55 UTC, Andre Pany wrote:
 On Thursday, 20 December 2018 at 14:17:11 UTC, unDEFER wrote:
 Hello!
 I know there is IDE tools like DCD, but I don't like it 
 because it hasn't UCFS-suggestions.
 So I have written my own patches to DMD to decide this 
 problem. The patches adds the "-interp" option to compiler. In 
 this mode the compiler is interrupted after semantic3 stage 
 and displays the next prompt:

 [...]
Without knowing the details I assume dcd is using libdparse and here some features are missing. If we could add the missing features to libdparse, dcd and also other tools would immediately profit (dscanner, dfrmt,...) Kind regards Andre
Unfortunately he's right about dparse. Dparse and dsymbols are really far from being able to give correct UFCS suggestions because 1. it does not do the semantic of expressions and statements This basically means that CTFE is not possible (mixin, static if) because before intepreting the expressions they must be analyzed but most importantly this means that the return type of auto functions cant be infered (it relies on the type of the expression wrapped in a return statement). 2. it does not instantiate templates AST copy and patch parameter with instances. So for now any attempt to implement UFCS suggestions will work to a very limited extant when trying to be type-correct. Some rules could be applied such as "if the type of the first parameter is not known then presume that by default it will work" but then the suggestions will be mostly wrong. If someone wants to give a try there's been an attempt from Soulaimane last year: https://github.com/SSoulaimane/dcd/commit/dc666817139e6fc135a6d02dc4dc63406aeca439
Dec 22 2018