Skip to content

Commit

Permalink
setup wiz tweaks; better handling for empty JSDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
wiggin77 committed Jan 11, 2017
1 parent a4de015 commit 376f098
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 20 deletions.
12 changes: 6 additions & 6 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

## Some todo's and bugs that I won't bother creating issues for

- Setup.applyConfig: filter out top-level properties of the wrong scope. (DONE)
- setup saving to USER overwrites existing params in USER; same for WORKSPACE (FIXED)

- when populating template, merge params from "*" and "haxe" such that haxe overrides "*".

- handle /** better for non-function comment --> end up with something like "\** | *\"
- (DONE) Setup.applyConfig: filter out top-level properties of the wrong scope.
- (FIXED) Setup saving to USER overwrites existing params in USER; same for WORKSPACE.
- (DONE) When populating template, merge params from "*" and "haxe" such that haxe overrides "*".
- (DONE) Handle /** better for non-function comment --> end up with something like "\** | *\"

- handle */ and **/ auto close brackets; Haxe uses **/ for some reason

- When preceeding a class declaration, create empty multi-line JSDoc.

- after setup wizard trigger by /* the re-running of cmd insert_file_header fails.
- only when writing to WORKSPACE settings; the new data is not available
until approx 1 sec delay (machine specific?), even though we wait for
Expand Down
29 changes: 22 additions & 7 deletions src/wiggin/codedox/CodeDox.hx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ import vscode.TextEditorEdit;
import vscode.TextDocumentChangeEvent;
import vscode.TextLine;
import vscode.Selection;
import vscode.Position;
import wiggin.codedox.FileHeader;
import wiggin.codedox.Commenter;
import wiggin.util.StringUtil;
import wiggin.util.ParseUtil;
using StringTools;

typedef Settings = {autoInsert:Bool, autoInsertHeader:Bool, strCommentBegin:String, strCommentEnd:String,
strCommentPrefix:String, strCommentDescription:String, strCommentTrigger:String,
Expand Down Expand Up @@ -274,34 +276,47 @@ class CodeDox

if(StringUtil.hasChars(strChangeText))
{
if(m_commenter != null && m_commenter.isInsertPending && strChangeText.indexOf(settings.strCommentDescription) != -1)
if(m_commenter != null && m_commenter.isInsertPending)
{
// A comment insert was just performed and we need to put the cursor in the right place, and possibly
// select a comment decription so the user can just start typing to overwrite it.
m_commenter.isInsertPending = false;
var ft:FoundText = ParseUtil.findText(doc, change.range.start, settings.strCommentDescription);
if(ft != null)
if(strChangeText.indexOf(settings.strCommentDescription) != -1)
{
var sel:Selection = new Selection(ft.posEnd, ft.posStart);
editor.selection = sel;
var ft:FoundText = ParseUtil.findText(doc, change.range.start, settings.strCommentDescription);
if(ft != null)
{
editor.selection = new Selection(ft.posEnd, ft.posStart);
}
}
else if(strChangeText.trim() == settings.strCommentBegin + " " + settings.strCommentEnd)
{
var ft:FoundText = ParseUtil.findText(doc, change.range.start, settings.strCommentBegin);
if(ft != null)
{
var p:Position = new Position(ft.posEnd.line, ft.posEnd.character + 1);
editor.selection = new Selection(p, p);
}
}
}
else if(settings.autoInsertHeader && strChangeText == settings.strHeaderTrigger &&
doc.offsetAt(change.range.end) == 1 && change.range.isEmpty)
{
// A header comment trigger was typed at the top of file.
var line = doc.lineAt(0);
if(line.text == settings.strHeaderBegin)
{
//js.Node.setTimeout(function() { doHeaderInsert(line, editor); }, 0);
doHeaderInsert(line, editor);
}
}
else if(settings.autoInsert && strChangeText == settings.strCommentTrigger ||
strChangeText == settings.strCommentTrigger + settings.strAutoClosingClose)
{
// A function comment trigger was typed.
var line = doc.lineAt(change.range.start.line);
var strCheck = StringUtil.trim(line.text);
if(strCheck == settings.strCommentBegin || strCheck == settings.strCommentBegin + settings.strAutoClosingClose)
{
//js.Node.setTimeout(function() { doCommentInsert(line, editor); }, 0);
doCommentInsert(line, editor);
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/wiggin/codedox/Commenter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ package wiggin.codedox;
import vscode.TextEditorEdit;
import vscode.TextEditor;
import vscode.TextLine;
import vscode.Position;
import wiggin.util.StringUtil;
import wiggin.util.MathUtil;
import wiggin.util.ParseUtil;
import wiggin.util.ParseUtil.Direction;

typedef Param = {name:String, type:String}
typedef FunctionInfo = {params:Array<Param>, retType:String, strIndent:String}
Expand Down Expand Up @@ -124,6 +126,14 @@ class Commenter

strComment = composeComment(strIndent, arrParams, strReturnType);
}
else
{
// Figure out the indentation used by counting whitespace at the
// beginning of the next non-blank line.
var lineCheck:TextLine = ParseUtil.findLine(doc, new Position(posStart.line + 1, 0), Direction.Forward, ~/[^\s]+/);
var strIndent = (lineCheck != null) ? ParseUtil.getIndent(doc, lineCheck.range.start) : "";
strComment = strIndent + settings.strCommentBegin + " " + settings.strCommentEnd + "\n";
}
}
return strComment;
}
Expand Down
9 changes: 4 additions & 5 deletions src/wiggin/codedox/FileHeader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import wiggin.codedox.License;
import wiggin.util.JsonUtil;
import wiggin.util.RegExUtil;
import wiggin.util.ConfigUtil;
import wiggin.util.StructUtil;

/**
* Implements command for inserting file header at top of files.
Expand Down Expand Up @@ -156,11 +157,9 @@ class FileHeader
*/
private function populateTemplate(config:WorkspaceConfiguration, strTemplate:String, strLang:String) : String
{
var params:Dynamic = config.get(PARAMS + "." + strLang, null);
if(params == null)
{
params = config.get(PARAMS + ".*", null);
}
var paramsStar:Dynamic = config.get(PARAMS + ".*", null);
var paramsLang:Dynamic = config.get(PARAMS + "." + strLang, null);
var params:Dynamic = StructUtil.mergeStruct(paramsStar, paramsLang);

var mapParams:Map<String,Dynamic> = JsonUtil.isStruct(params) ? JsonUtil.structToMap(params) : new Map();

Expand Down
10 changes: 8 additions & 2 deletions src/wiggin/codedox/Setup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import wiggin.codedox.License;
import wiggin.util.ConfigUtil;
import wiggin.util.StructUtil;
import wiggin.util.StringUtil;
import wiggin.util.DynamicObject;


typedef Transaction = {scope:Scope, obj:{}}

Expand Down Expand Up @@ -155,7 +157,11 @@ class Setup
{
if(StringUtil.hasChars(strInput))
{
var update = {fileheader:{params:{"*":{company:strInput}}}};
var editor = Vscode.window.activeTextEditor;
var paramBranch = (editor != null) ? editor.document.languageId : "*";
var param:DynamicObject<Dynamic> = {};
param.set(paramBranch, {company:strInput});
var update = {fileheader:{params:param}};
m_transaction.obj = StructUtil.mergeStruct(m_transaction.obj, update);
resolve(true);
}
Expand Down Expand Up @@ -227,7 +233,7 @@ class Setup
var config = Vscode.workspace.getConfiguration();
var strCompany= null;
var editor = Vscode.window.activeTextEditor;
if(editor == null)
if(editor != null)
{
strCompany = config.get(FileHeader.PARAMS + "." + editor.document.languageId + ".company", null);
}
Expand Down

0 comments on commit 376f098

Please sign in to comment.