From 7eeb5dbe0af55958222d5b323246d8b328c5e4c9 Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Sun, 30 Apr 2017 10:35:08 +0200 Subject: [PATCH] ddoc template, add option to insert /++ +/ comments --- dastworx/src/ddoc_template.d | 54 +++++++++++++++++++----------------- dastworx/src/main.d | 11 ++++++-- src/ce_dastworx.pas | 6 ++-- src/ce_editoroptions.pas | 4 +++ src/ce_symlist.pas | 2 +- src/ce_synmemo.pas | 4 ++- 6 files changed, 49 insertions(+), 32 deletions(-) diff --git a/dastworx/src/ddoc_template.d b/dastworx/src/ddoc_template.d index 20a34b53..c39a560a 100644 --- a/dastworx/src/ddoc_template.d +++ b/dastworx/src/ddoc_template.d @@ -11,9 +11,9 @@ import * Finds the declaration at caretLine and write its ddoc template * in the standard output. */ -void getDdocTemplate(const(Module) mod, int caretLine) +void getDdocTemplate(const(Module) mod, int caretLine, bool plusComment) { - DDocTemplateGenerator dtg = construct!DDocTemplateGenerator(caretLine); + DDocTemplateGenerator dtg = construct!DDocTemplateGenerator(caretLine, plusComment); dtg.visit(mod); } @@ -23,24 +23,28 @@ final class DDocTemplateGenerator: ASTVisitor private: - int _caretline; + immutable int _caretline; + immutable char c1; + immutable char[2] c2; public: - this(int caretline) + this(int caretline, bool plusComment) { _caretline = caretline; + c1 = plusComment ? '+' : '*'; + c2 = plusComment ? "++" : "**"; } override void visit(const(FunctionDeclaration) decl) { if (decl.name.line == _caretline) { - writeln("/**\n * \n * \n * \n *"); + writeln("/", c2, "\n ", c1, " \n ", c1, " \n ", c1, " \n ", c1); if (decl.templateParameters || decl.parameters) { - writeln(" * Params:"); + writeln(" ", c1, " Params:"); if (decl.templateParameters && decl.templateParameters.templateParameterList) { @@ -48,13 +52,13 @@ public: .templateParameterList.items) { if (p.templateAliasParameter) - writeln(" * ", p.templateAliasParameter.identifier.text, " = "); + writeln(" ", c1, " ", p.templateAliasParameter.identifier.text, " = "); else if (p.templateTupleParameter) - writeln(" * ", p.templateTupleParameter.identifier.text, " = "); + writeln(" ", c1, " ", p.templateTupleParameter.identifier.text, " = "); else if (p.templateTypeParameter) - writeln(" * ", p.templateTypeParameter.identifier.text, " = "); + writeln(" ", c1, " ", p.templateTypeParameter.identifier.text, " = "); else if (p.templateValueParameter) - writeln(" * ", p.templateValueParameter.identifier.text, " = "); + writeln(" ", c1, " ", p.templateValueParameter.identifier.text, " = "); } } if (decl.parameters) @@ -62,9 +66,9 @@ public: foreach(i, const Parameter p; decl.parameters.parameters) { if (p.name.text != "") - writeln(" * ", p.name.text, " = "); + writeln(" ", c1, " ", p.name.text, " = "); else - writeln(" * __param", i, " = "); + writeln(" ",c1, " __param", i, " = "); } } } @@ -73,10 +77,10 @@ public: { if (decl.returnType.type2 && decl.returnType.type2 && decl.returnType.type2.builtinType != tok!"void") - writeln(" * \n * Returns: "); + writeln(" ", c1, " \n ", c1, " Returns: "); } - writeln(" */"); + writeln(" ", c1, "/"); } else if (decl.name.line > _caretline) @@ -108,11 +112,11 @@ public: { if (decl.name.line == _caretline) { - writeln("/**\n * \n * \n * \n *"); + writeln("/", c2, "\n ", c1, " \n ", c1, " \n ", c1, " \n ", c1); if (decl.templateParameters) { - writeln(" * Params:"); + writeln(" ", c1, " Params:"); if (decl.templateParameters && decl.templateParameters.templateParameterList) { @@ -120,18 +124,18 @@ public: .templateParameterList.items) { if (p.templateAliasParameter) - writeln(" * ", p.templateAliasParameter.identifier.text, " = "); + writeln(" ", c1, " ", p.templateAliasParameter.identifier.text, " = "); else if (p.templateTupleParameter) - writeln(" * ", p.templateTupleParameter.identifier.text, " = "); + writeln(" ", c1, " ", p.templateTupleParameter.identifier.text, " = "); else if (p.templateTypeParameter) - writeln(" * ", p.templateTypeParameter.identifier.text, " = "); + writeln(" ", c1, " ", p.templateTypeParameter.identifier.text, " = "); else if (p.templateValueParameter) - writeln(" * ", p.templateValueParameter.identifier.text, " = "); + writeln(" ", c1, " ", p.templateValueParameter.identifier.text, " = "); } } } - writeln(" */"); + writeln(" ", c1, "/"); } else if (decl.name.line > _caretline) @@ -142,7 +146,7 @@ public: version(unittest) { - DDocTemplateGenerator parseAndVisit(const(char)[] source, int caretLine) + DDocTemplateGenerator parseAndVisit(const(char)[] source, int caretLine, bool p = false) { writeln; RollbackAllocator allocator; @@ -150,7 +154,7 @@ version(unittest) StringCache cache = StringCache(StringCache.defaultBucketCount); const(Token)[] tokens = getTokensForParser(cast(ubyte[]) source, config, &cache); Module mod = parseModule(tokens, "", &allocator); - DDocTemplateGenerator result = construct!(DDocTemplateGenerator)(caretLine); + DDocTemplateGenerator result = construct!(DDocTemplateGenerator)(caretLine, p); result.visit(mod); return result; } @@ -160,7 +164,7 @@ unittest { q{ module a; void foo(A...)(A a){} - }.parseAndVisit(2); + }.parseAndVisit(2, true); } unittest @@ -174,7 +178,7 @@ unittest { q{ module a; int foo(int){} - }.parseAndVisit(2); + }.parseAndVisit(2, true); } unittest diff --git a/dastworx/src/main.d b/dastworx/src/main.d index 827c9656..f3caa75b 100644 --- a/dastworx/src/main.d +++ b/dastworx/src/main.d @@ -13,11 +13,16 @@ import private __gshared int caretLine; -private __gshared bool deepSymList; +private __gshared bool option1; private __gshared static Appender!(ubyte[]) source; private __gshared static Appender!(AstErrors) errors; private __gshared string[] files; +// -o : deep visit the symbols +alias deepSymList = option1; +// -o : outputs /++ +/ ddoc instead of /** */ +alias plusComment = option1; + static this() { GC.disable; @@ -51,7 +56,7 @@ void main(string[] args) // options for the work getopt(args, std.getopt.config.passThrough, - "d", &deepSymList, + "o", &option1, "l", &caretLine ); @@ -152,7 +157,7 @@ void handleDdocTemplateOption() source.data .getTokensForParser(config, &cache) .parseModule("", &alloc, &ignoreErrors) - .getDdocTemplate(caretLine); + .getDdocTemplate(caretLine, plusComment); } private void handleErrors(string fname, size_t line, size_t col, string message, diff --git a/src/ce_dastworx.pas b/src/ce_dastworx.pas index 31566807..97d27a5d 100644 --- a/src/ce_dastworx.pas +++ b/src/ce_dastworx.pas @@ -22,7 +22,7 @@ procedure getModulesImports(const files: string; results: TStrings); procedure getHalsteadMetrics(source: TStrings; out jsn: TJSONObject); -procedure getDdocTemplate(source, res: TStrings;caretLine: integer); +procedure getDdocTemplate(source, res: TStrings;caretLine: integer; plusComment: boolean); implementation @@ -127,7 +127,7 @@ begin end; end; -procedure getDdocTemplate(source, res: TStrings; caretLine: integer); +procedure getDdocTemplate(source, res: TStrings; caretLine: integer; plusComment: boolean); var prc: TProcess; str: string; @@ -140,6 +140,8 @@ begin prc.Executable := str; prc.Parameters.Add('-K'); prc.Parameters.Add('-l' + caretLine.ToString); + if plusComment then + prc.Parameters.Add('-o'); prc.Options := [poUsePipes {$IFDEF WINDOWS}, poNewConsole{$ENDIF}]; prc.ShowWindow := swoHIDE; prc.Execute; diff --git a/src/ce_editoroptions.pas b/src/ce_editoroptions.pas index 36e4226e..731c0c62 100644 --- a/src/ce_editoroptions.pas +++ b/src/ce_editoroptions.pas @@ -63,6 +63,7 @@ type fAlwaysAdvancedFeatures: boolean; fAutoClosedPairs: TAutoClosePairs; fSmartDdocNewline: boolean; + fInsertPlusDdoc: boolean; // procedure setPhobosDocRoot(value: TCEPathname); procedure setFont(value: TFont); @@ -107,6 +108,7 @@ type property options1: TSynEditorOptions read fOptions1 write fOptions1; property options2: TSynEditorOptions2 read fOptions2 write fOptions2; property phobosDocRoot: TCEPathname read fPhobosDocRoot write setPhobosDocRoot; + property plusDdoc: boolean read fInsertPlusDdoc write fInsertPlusDdoc; property resetFontSize: boolean read fResetFontSize write fResetFontSize default true; property rightEdge: Integer read fRightEdge write fRightEdge default 80; property rightEdgeColor: TColor read fRightEdgeColor write fRightEdgeColor default clSilver; @@ -304,6 +306,7 @@ begin identifierMatchOptions:=srcopt.identifierMatchOptions; detectIndentMode:=srcopt.detectIndentMode; fPhobosDocRoot:=srcopt.fPhobosDocRoot; + fInsertPlusDdoc:= srcopt.fInsertPlusDdoc; fSmartDdocNewline:=srcopt.fSmartDdocNewline; if fSmartDdocNewline then @@ -674,6 +677,7 @@ begin anEditor.phobosDocRoot:=fPhobosDocRoot; anEditor.alwaysAdvancedFeatures:=fAlwaysAdvancedFeatures; anEditor.smartDdocNewline:= fSmartDdocNewline; + anEditor.insertPlusDdoc:= fInsertPlusDdoc; for i := 0 to anEditor.Keystrokes.Count-1 do begin kst := anEditor.Keystrokes.Items[i]; diff --git a/src/ce_symlist.pas b/src/ce_symlist.pas index a4cef914..32bfdcfb 100644 --- a/src/ce_symlist.pas +++ b/src/ce_symlist.pas @@ -685,7 +685,7 @@ begin fToolProc.OnTerminate := @toolTerminated; fToolProc.CurrentDirectory := Application.ExeName.extractFileDir; if fDeep then - fToolProc.Parameters.Add('-d'); + fToolProc.Parameters.Add('-o'); fToolProc.Parameters.Add('-s'); fToolProc.Execute; str := fDoc.Text; diff --git a/src/ce_synmemo.pas b/src/ce_synmemo.pas index 3a7af5fa..c34a6b78 100644 --- a/src/ce_synmemo.pas +++ b/src/ce_synmemo.pas @@ -181,6 +181,7 @@ type fHasModuleDeclaration: boolean; fLastCompletion: string; fDebugger: ICEDebugger; + fInsertPlusDdoc: boolean; procedure decCallTipsLvl; procedure setMatchOpts(value: TIdentifierMatchOptions); function getMouseBytePosition: Integer; @@ -305,6 +306,7 @@ type property autoCloseCurlyBrace: TBraceAutoCloseStyle read fAutoCloseCurlyBrace write fAutoCloseCurlyBrace; property autoClosedPairs: TAutoClosePairs read fAutoClosedPairs write fAutoClosedPairs; property smartDdocNewline: boolean read fSmartDdocNewline write fSmartDdocNewline; + property insertPlusDdoc: boolean read fInsertPlusDdoc write fInsertPlusDdoc; end; TSortDialog = class(TForm) @@ -1872,7 +1874,7 @@ var begin d := TStringList.Create; try - getDdocTemplate(lines, d, CaretY); + getDdocTemplate(lines, d, CaretY, fInsertPlusDdoc); if d.Text.isNotEmpty then begin BeginUndoBlock;