Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/LanguageServer/IdePurescript/CodeActions.purs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import LanguageServer.Protocol.Text (makeWorkspaceEdit)
import LanguageServer.Protocol.TextDocument (TextDocument, getTextAtRange, getVersion)
import LanguageServer.Protocol.Types (ClientCapabilities, CodeAction(..), CodeActionKind(..), CodeActionResult, Command(..), DocumentStore, DocumentUri(DocumentUri), OptionalVersionedTextDocumentIdentifier(..), Position(Position), Range(Range), Settings, TextDocumentEdit(..), TextDocumentIdentifier(TextDocumentIdentifier), TextEdit(..), codeActionEmpty, codeActionResult, codeActionSourceOrganizeImports, codeActionSourceSortImports, readRange, workspaceEdit)
import PscIde.Command (PscSuggestion(..), PursIdeInfo(..), RebuildError(..))
import Untagged.Union (maybeToUor, uorToMaybe)

getActions ::
DocumentStore ->
Expand Down Expand Up @@ -200,8 +201,7 @@ codeActionToCommand capabilities action =
convert action
where
supportsLiteral = maybe true codeActionLiteralsSupported capabilities
convert (CodeAction { command }) | Just c <- Nullable.toMaybe command = Just $
Right c
convert (CodeAction { command }) | Just c <- uorToMaybe command = Just $ Right c
convert _ = Nothing

commandAction :: CodeActionKind -> Command -> CodeAction
Expand All @@ -210,8 +210,8 @@ commandAction kind c@(Command { title }) =
{ title
, kind
, isPreferred: false
, edit: Nullable.toNullable Nothing
, command: Nullable.toNullable $ Just c
, edit: maybeToUor Nothing
, command: maybeToUor $ Just c
}

commandAction_ :: Command -> CodeAction
Expand Down
4 changes: 2 additions & 2 deletions src/LanguageServer/Protocol/Types.purs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ newtype CodeAction = CodeAction
{ title :: String
, kind :: CodeActionKind
, isPreferred :: Boolean
, edit :: Nullable WorkspaceEdit
, command :: Nullable Command
, edit :: UndefinedOr WorkspaceEdit
, command :: UndefinedOr Command
}

foreign import data CodeActionResult :: Type
Expand Down
1 change: 1 addition & 0 deletions test/Main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const stringifyCodeAction = (action) => JSON.stringify(action);
22 changes: 21 additions & 1 deletion test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ import Data.Maybe (Maybe(..), fromMaybe)
import Data.Nullable (null, toMaybe)
import Data.Nullable as Nullable
import Effect (Effect)
import Foreign (unsafeToForeign)
import IdePurescript.Tokens (identifierAtPoint)
import LanguageServer.IdePurescript.FileTypes (RelevantFileType(..), jsUriToMayPsUri, uriToRelevantFileType)
import LanguageServer.Protocol.Text (makeMinimalWorkspaceEdit)
import LanguageServer.Protocol.Types (ClientCapabilities, DocumentUri(..), Position(..), Range(..), TextDocumentEdit(..), TextEdit(..), WorkspaceEdit(..))
import LanguageServer.Protocol.Types (ClientCapabilities, CodeAction(..), Command(..), DocumentUri(..), Position(..), Range(..), TextDocumentEdit(..), TextEdit(..), WorkspaceEdit(..), codeActionSourceSortImports)
import Test.Unit (suite, test)
import Test.Unit.Assert as Assert
import Test.Unit.Main (runTest)
import Untagged.Union (maybeToUor)

foreign import stringifyCodeAction :: CodeAction -> String

getEdit :: WorkspaceEdit -> Array TextEdit
getEdit (WorkspaceEdit { documentChanges }) = concat $ map go $ changes
Expand Down Expand Up @@ -76,6 +80,22 @@ main =
-- If I have a CRLF file for some reason but IDE server gives me back LF
let edit = makeEdit "A\r\nC\r\n" "A\nB\nC\n"
Assert.equal (Just [ mkEdit 1 1 "B\n" ]) (getEdit <$> edit)
test "command-only code action omits edit when serialized" do
let
action = CodeAction
{ title: "Sort/reformat imports"
, kind: codeActionSourceSortImports
, isPreferred: false
, edit: maybeToUor Nothing
, command: maybeToUor $ Just $ Command
{ title: "Sort/reformat imports"
, command: "sortImports"
, arguments: Nullable.notNull [ unsafeToForeign "uri" ]
}
}
Assert.equal
"""{"title":"Sort/reformat imports","kind":"source.sortImports","isPreferred":false,"command":{"title":"Sort/reformat imports","command":"sortImports","arguments":["uri"]}}"""
(stringifyCodeAction action)
-- Type at point
test "identifierAtPoint: identifies $" do
let str = """$"""
Expand Down