From 45175bbc91fb48f05724b0fec773e309f3e976f3 Mon Sep 17 00:00:00 2001 From: Christoph Schlosser Date: Fri, 30 Mar 2018 00:01:03 +0200 Subject: =?UTF-8?q?Don=E2=80=99t=20trigger=20comment=20generation=20while?= =?UTF-8?q?=20in=20comment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CodeParserController.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src') diff --git a/src/CodeParserController.ts b/src/CodeParserController.ts index 6dfc263..04928e8 100644 --- a/src/CodeParserController.ts +++ b/src/CodeParserController.ts @@ -70,6 +70,11 @@ export default class CodeParserController { return false; } + // Check if currently in a comment block + if (this.inComment(activeEditor, activeSelection.line)) { + return false; + } + // Do not trigger when there's whitespace after the trigger sequence // tslint:disable-next-line:max-line-length const seq = "[\\s]*(" + this.cfg.C.triggerSequence.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") + ")$"; @@ -83,6 +88,20 @@ export default class CodeParserController { } } + private inComment(activeEditor: TextEditor, activeLine: number): boolean { + if (activeLine === 0) { + return false; + } + + const txt: string = activeEditor.document.lineAt(activeLine - 1).text.trim(); + if (!txt.startsWith("///") && !txt.startsWith("*") && + !txt.startsWith("/**") && !txt.startsWith("/*!")) { + return false; + } else { + return true; + } + } + private onEvent(activeEditor: TextEditor, event: TextDocumentContentChangeEvent) { if (!this.check(activeEditor, event)) { return null; -- cgit v1.2.3