From b6dd45bc632055217aa78b176c52346bac56c711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Tetsing?= Date: Tue, 11 Jun 2024 12:19:47 +0200 Subject: [PATCH] fixed generated documentation identation --- .../src/app/tabs/locales/en/editor.json | 2 +- .../lib/providers/documentationProvider.ts | 5 +++ .../editor/src/lib/remix-ui-editor.tsx | 36 ++++++++++++------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/locales/en/editor.json b/apps/remix-ide/src/app/tabs/locales/en/editor.json index b9c8c33568..f68c83026f 100644 --- a/apps/remix-ide/src/app/tabs/locales/en/editor.json +++ b/apps/remix-ide/src/app/tabs/locales/en/editor.json @@ -21,7 +21,7 @@ "editor.formatCode": "Format Code", "editor.generateDocumentation": "Generate documentation for this function", "editor.generateDocumentation2": "Generate documentation for the function \"{name}\"", - "editor.generateDocumentationByAI": "solidity code: {content}\n Generate the natspec documentation for the function {currentFunction} using the Doxygen style syntax", + "editor.generateDocumentationByAI": "solidity code: {content}\n Generate the natspec documentation for the function {currentFunction} using the docstring style syntax. Only use docstring supported tags", "editor.explainFunction": "Explain this function", "editor.explainFunctionSol": "Explain this code", "editor.explainFunction2": "Explain the function \"{name}\"", diff --git a/libs/remix-ui/editor/src/lib/providers/documentationProvider.ts b/libs/remix-ui/editor/src/lib/providers/documentationProvider.ts index 03736935ba..0450339124 100644 --- a/libs/remix-ui/editor/src/lib/providers/documentationProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/documentationProvider.ts @@ -31,4 +31,9 @@ export class RemixSolidityDocumentationProvider implements monacoTypes.languages freeInlineCompletions(completions: monacoTypes.languages.InlineCompletions): void { } + groupId?: string; + yieldsToGroupIds?: string[]; + toString?(): string { + throw new Error('Method not implemented.'); + } } \ No newline at end of file diff --git a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx index 773ecd7414..d77108c1ad 100644 --- a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx +++ b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx @@ -733,6 +733,7 @@ export const EditorUI = (props: EditorUIProps) => { monacoRef.current.KeyMod.CtrlCmd | monacoRef.current.KeyCode.KeyD ], run: async () => { + const unsupportedDocTags = ['@title'] // these tags are not supported by the current docstring parser const file = await props.plugin.call('fileManager', 'getCurrentFile') const content = await props.plugin.call('fileManager', 'readFile', file) const message = intl.formatMessage({ id: 'editor.generateDocumentationByAI' }, { content, currentFunction: currentFunction.current }) @@ -740,29 +741,38 @@ export const EditorUI = (props: EditorUIProps) => { const natspecCom = "\n" + extractNatspecComments(cm) const cln = await props.plugin.call('codeParser', "getLineColumnOfNode", currenFunctionNode) - const range = new monacoRef.current.Range(cln.start.line, editor.getModel().getLineMaxColumn(cln.start.line), cln.start.line, cln.start.column) + const range = new monacoRef.current.Range(cln.start.line, cln.start.column, cln.start.line, cln.start.column) + + const lines = natspecCom.split('\n') + const newnatspeccom = [] //natspecCom.split('\n').map((line => ' '.repeat(cln.start.column) + line.trimStart())).join('\n') + + for (let i = 0; i < lines.length; i++) { + let cont = false + + for (let j = 0; j < unsupportedDocTags.length; j++) { + if (lines[i].includes(unsupportedDocTags[j])) { + cont = true + break + } + } + if (cont) {continue} + + if (i <= 1) { newnatspeccom.push(' '.repeat(cln.start.column) + lines[i].trimStart()) } + else { newnatspeccom.push(' '.repeat(cln.start.column + 1) + lines[i].trimStart()) } + } // TODO: activate the provider to let the user accept the documentation suggestion // const provider = new RemixSolidityDocumentationProvider(natspecCom) - // editor.inlineProviderDisposable = monacoRef.current.languages.registerInlineCompletionsProvider('remix-docu', provider) - // const acts = editor.getActions() - // console.log(acts) + // monacoRef.current.languages.registerInlineCompletionsProvider('solidity', provider) - editor.executeEdits('inlineCompletionDocu', [ + editor.executeEdits('clipboard', [ { range: range, - text: natspecCom, + text: newnatspeccom.join('\n'), forceMoveMarkers: true, }, ]); - const endline = cln.start.line + natspecCom.split('\n').length-1 - const selection = new monacoRef.current.Selection(cln.start.line+1, 0, endline , editor.getModel().getLineMaxColumn(endline)); - editor.setSelection(selection); - editor.revealLinesInCenter(cln.start.line+1, endline); - - editor.trigger("editor", "editor.action.indentLines"); - _paq.push(['trackEvent', 'ai', 'solcoder', 'generateDocumentation']) }, }