mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[js] WEB-41356 compute types on BGT for doc comment generation
GitOrigin-RevId: f3869a6b1e4692ae632b16d658700b6e25289ba8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e294c2f5c9
commit
ffbacb2461
+15
-1
@@ -1,10 +1,12 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
|
||||
package com.intellij.lang.documentation;
|
||||
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -51,4 +53,16 @@ public interface CodeDocumentationProvider extends DocumentationProvider {
|
||||
*/
|
||||
@Nullable
|
||||
String generateDocumentationContentStub(PsiComment contextComment);
|
||||
|
||||
/**
|
||||
* Works like {@link #generateDocumentationContentStub(PsiComment)}, but inserts generated content into the document.
|
||||
* @param contextComment context psi comment
|
||||
* @param document document to insert generated content into
|
||||
* @param offset offset in the document to insert generated content at
|
||||
* @return true if documentation content was generated and inserted into the document, false otherwise
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
default boolean insertDocumentationContentStub(@NotNull PsiComment contextComment, @NotNull Document document, int offset) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
|
||||
package com.intellij.codeInsight.editorActions;
|
||||
|
||||
@@ -611,12 +611,20 @@ public class EnterHandler extends BaseEnterHandler {
|
||||
|
||||
if (docProvider != null) {
|
||||
if (docProvider.findExistingDocComment(comment) != comment) return comment;
|
||||
String docStub = DumbService.getInstance(project).computeWithAlternativeResolveEnabled(() -> docProvider.generateDocumentationContentStub(comment));
|
||||
|
||||
if (docStub != null && !docStub.isEmpty()) {
|
||||
myOffset = CharArrayUtil.shiftForwardUntil(myDocument.getCharsSequence(), myOffset, LINE_SEPARATOR);
|
||||
myOffset = CharArrayUtil.shiftForward(myDocument.getCharsSequence(), myOffset, LINE_SEPARATOR);
|
||||
myDocument.insertString(myOffset, docStub);
|
||||
int newOffset = CharArrayUtil.shiftForwardUntil(myDocument.getCharsSequence(), myOffset, LINE_SEPARATOR);
|
||||
newOffset = CharArrayUtil.shiftForward(myDocument.getCharsSequence(), newOffset, LINE_SEPARATOR);
|
||||
if (docProvider.insertDocumentationContentStub(comment, myDocument, newOffset)) {
|
||||
myOffset = newOffset;
|
||||
}
|
||||
else {
|
||||
String docStub = DumbService.getInstance(project)
|
||||
.computeWithAlternativeResolveEnabled(() -> docProvider.generateDocumentationContentStub(comment));
|
||||
|
||||
if (docStub != null && !docStub.isEmpty()) {
|
||||
myOffset = newOffset;
|
||||
myDocument.insertString(myOffset, docStub);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-5
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.editorActions;
|
||||
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
@@ -227,10 +227,16 @@ public final class FixDocCommentAction extends EditorAction {
|
||||
return;
|
||||
}
|
||||
|
||||
String stub = documentationProvider.generateDocumentationContentStub(pair.second);
|
||||
if (stub != null) {
|
||||
int insertionOffset = commentStartOffset + commentBodyRelativeOffset;
|
||||
document.insertString(insertionOffset, stub);
|
||||
int insertionOffset = commentStartOffset + commentBodyRelativeOffset;
|
||||
boolean inserted = documentationProvider.insertDocumentationContentStub(pair.second, document, insertionOffset);
|
||||
if (!inserted) {
|
||||
String stub = documentationProvider.generateDocumentationContentStub(pair.second);
|
||||
if (stub != null) {
|
||||
document.insertString(insertionOffset, stub);
|
||||
inserted = true;
|
||||
}
|
||||
}
|
||||
if (inserted) {
|
||||
docManager.commitDocument(document);
|
||||
pair = documentationProvider.parseContext(anchor);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user