Skip to content

Commit

Permalink
Change the codeAction method signature
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperFKorban authored and tgodzik committed Sep 17, 2024
1 parent f242b25 commit eb2cdb8
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import scala.meta.internal.{semanticdb => s}
import scala.meta.io.AbsolutePath
import scala.meta.pc.AutoImportsResult
import scala.meta.pc.CancelToken
import scala.meta.pc.CodeActionId
import scala.meta.pc.CompletionItemPriority
import scala.meta.pc.HoverSignature
import scala.meta.pc.OffsetParams
Expand Down Expand Up @@ -884,7 +883,7 @@ class Compilers(
def codeAction(
params: TextDocumentPositionParams,
token: CancelToken,
codeActionId: CodeActionId,
codeActionId: String,
codeActionPayload: Object,
): Future[ju.List[TextEdit]] = {
withPCAndAdjustLsp(params) { (pc, pos, adjust) =>
Expand All @@ -903,7 +902,7 @@ class Compilers(
}
}.getOrElse(Future.successful(Nil.asJava))

def supportedCodeActions(path: AbsolutePath): ju.List[CodeActionId] = {
def supportedCodeActions(path: AbsolutePath): ju.List[String] = {
loadCompiler(path).map { pc =>
pc.supportedCodeActions()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import scala.concurrent.Future
import scala.meta.internal.metals.MetalsEnrichments._
import scala.meta.internal.metals.ParametrizedCommand
import scala.meta.pc.CancelToken
import scala.meta.pc.CodeActionId

import org.eclipse.{lsp4j => l}

Expand All @@ -23,7 +22,7 @@ trait CodeAction {
* The CodeActionId for this code action, if applicable. CodeActionId is only
* used for code actions that require the use of the presentation compiler.
*/
def maybeCodeActionId: Option[CodeActionId] = None
def maybeCodeActionId: Option[String] = None

type CommandData
type ActionCommand = ParametrizedCommand[CommandData]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,15 @@ final class CodeActionProvider(
new ActionableDiagnostic(),
new StringActions(buffers),
extractMemberAction,
new SourceOrganizeImports(
scalafixProvider,
buildTargets,
diagnostics,
),
new OrganizeImportsQuickFix(
scalafixProvider,
buildTargets,
diagnostics,
),
new SourceOrganizeImports(scalafixProvider, buildTargets, diagnostics),
new OrganizeImportsQuickFix(scalafixProvider, buildTargets, diagnostics),
new InsertInferredType(trees, compilers, languageClient),
new PatternMatchRefactor(trees),
new RewriteBracesParensCodeAction(trees),
new ExtractValueCodeAction(trees, buffers),
new CreateCompanionObjectCodeAction(trees, buffers),
new ExtractMethodCodeAction(trees, compilers, languageClient),
new InlineValueCodeAction(
trees,
compilers,
languageClient,
),
new InlineValueCodeAction(trees, compilers, languageClient),
new ConvertToNamedArguments(trees, compilers, languageClient),
new FlatMapToForComprehensionCodeAction(trees, buffers),
new MillifyDependencyCodeAction(buffers),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import scala.meta.internal.metals.codeactions.CodeActionBuilder
import scala.meta.internal.metals.logging
import scala.meta.internal.parsing.Trees
import scala.meta.pc.CancelToken
import scala.meta.pc.CodeActionId

import org.eclipse.{lsp4j => l}

Expand All @@ -29,8 +28,8 @@ class ConvertToNamedArguments(
import ConvertToNamedArguments._
override val kind: String = l.CodeActionKind.RefactorRewrite

override val maybeCodeActionId: Option[CodeActionId] = Some(
CodeActionId.ConvertToNamedArguments
override val maybeCodeActionId: Option[String] = Some(
"ConvertToNamedArguments"
)

override type CommandData = ServerCommands.ConvertToNamedArgsRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import scala.meta.internal.metals.clients.language.MetalsLanguageClient
import scala.meta.internal.metals.logging
import scala.meta.internal.parsing.Trees
import scala.meta.pc.CancelToken
import scala.meta.pc.CodeActionId

import org.eclipse.lsp4j.CodeActionParams
import org.eclipse.{lsp4j => l}
Expand All @@ -33,8 +32,8 @@ class ExtractMethodCodeAction(
)
override def kind: String = l.CodeActionKind.RefactorExtract

override val maybeCodeActionId: Option[CodeActionId] = Some(
CodeActionId.ExtractMethod
override val maybeCodeActionId: Option[String] = Some(
"ExtractMethod"
)

override def handleCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ import scala.meta.internal.metals.MetalsEnrichments._
import scala.meta.internal.metals.ScalacDiagnostic
import scala.meta.internal.metals.codeactions.CodeAction
import scala.meta.pc.CancelToken
import scala.meta.pc.CodeActionId

import org.eclipse.{lsp4j => l}

class ImplementAbstractMembers(compilers: Compilers) extends CodeAction {

override def kind: String = l.CodeActionKind.QuickFix

override val maybeCodeActionId: Option[CodeActionId] = Some(
CodeActionId.ImplementAbstractMembers
override val maybeCodeActionId: Option[String] = Some(
"ImplementAbstractMembers"
)

override def contribute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import scala.meta.internal.metals.ScalaVersions
import scala.meta.internal.metals.ScalacDiagnostic
import scala.meta.internal.metals.codeactions.CodeAction
import scala.meta.pc.CancelToken
import scala.meta.pc.CodeActionId

import org.eclipse.{lsp4j => l}

Expand All @@ -19,8 +18,8 @@ class ImportMissingSymbol(compilers: Compilers, buildTargets: BuildTargets)

override def kind: String = l.CodeActionKind.QuickFix

override val maybeCodeActionId: Option[CodeActionId] = Some(
CodeActionId.ImportMissingSymbol
override val maybeCodeActionId: Option[String] = Some(
"ImportMissingSymbol"
)

override def contribute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import scala.meta.internal.metals.codeactions.CodeAction
import scala.meta.internal.parsing.Trees
import scala.meta.io.AbsolutePath
import scala.meta.pc.CancelToken
import scala.meta.pc.CodeActionId

import org.eclipse.{lsp4j => l}

Expand All @@ -33,8 +32,8 @@ class InlineValueCodeAction(

override def kind: String = l.CodeActionKind.RefactorInline

override val maybeCodeActionId: Option[CodeActionId] = Some(
CodeActionId.InlineValue
override val maybeCodeActionId: Option[String] = Some(
"InlineValue"
)

override def contribute(params: l.CodeActionParams, token: CancelToken)(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import scala.meta.internal.metals.codeactions.CodeAction
import scala.meta.internal.metals.codeactions.CodeActionBuilder
import scala.meta.internal.parsing.Trees
import scala.meta.pc.CancelToken
import scala.meta.pc.CodeActionId

import org.eclipse.{lsp4j => l}

Expand All @@ -34,8 +33,8 @@ class InsertInferredType(
import InsertInferredType._
override def kind: String = l.CodeActionKind.QuickFix

override val maybeCodeActionId: Option[CodeActionId] = Some(
CodeActionId.InsertInferredType
override val maybeCodeActionId: Option[String] = Some(
"InsertInferredType"
)

override def handleCommand(
Expand Down
10 changes: 0 additions & 10 deletions mtags-interfaces/src/main/java/scala/meta/pc/CodeActionId.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,21 @@ public CompletableFuture<java.util.List<ReferencesResult>> references(References
/**
* Execute the given code action
*/
public CompletableFuture<List<TextEdit>> codeAction(OffsetParams params, CodeActionId codeActionId, Object codeActionPayload) {
public CompletableFuture<List<TextEdit>> codeAction(OffsetParams params, String codeActionId, Object codeActionPayload) {
return CompletableFuture.completedFuture(Collections.emptyList());
}

/**
* Returns the list of code actions supported by the current presentation compiler.
*/
public List<CodeActionId> supportedCodeActions() {
public List<String> supportedCodeActions() {
return Arrays.asList(
CodeActionId.ConvertToNamedArguments,
CodeActionId.ExtractMethod,
CodeActionId.ImplementAbstractMembers,
CodeActionId.ImportMissingSymbol,
CodeActionId.InlineValue,
CodeActionId.InsertInferredType
"ConvertToNamedArguments",
"ExtractMethod",
"ImplementAbstractMembers",
"ImportMissingSymbol",
"InlineValue",
"InsertInferredType"
);
}

Expand Down

0 comments on commit eb2cdb8

Please sign in to comment.