Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing assists/Start new line: support for patch engine #692

Merged
merged 5 commits into from
Aug 20, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,19 @@ type FSharpTypingAssist(lifetime, dependencies) as this =
let text = String(' ', indent) + this.GetNewLineText(textControl)
insertText textControl lineStartOffset text "Start New Line Before" (Some (lineStartOffset + indent))

let handleStartNewLinePressed (context: IActionContext) =
use _ = this.CommandProcessor.UsingCommand("Start New Line")

let textControl = context.TextControl
textControl.Selection.Delete()

let document = textControl.Document
let caretLine = textControl.Caret.Position.Value.ToDocLineColumn().Line
let lineEndOffset = document.GetLineEndOffsetNoLineBreak(caretLine)
textControl.Caret.MoveTo(lineEndOffset, CaretVisualPlacement.DontScrollIfVisible)

handleEnter(context)

let handleSpace (context: ITypingContext) =
this.HandleSpaceInsideEmptyBrackets(context.TextControl)

Expand All @@ -561,12 +574,13 @@ type FSharpTypingAssist(lifetime, dependencies) as this =
let isSmartParensHandlerAvailable = Predicate<_>(this.IsTypingSmartParenthesisHandlerAvailable2)
let manager = dependencies.TypingAssistManager

manager.AddActionHandler(lifetime, TextControlActions.ActionIds.Enter, this, Func<_,_>(handleEnter), isActionHandlerAvailable)
manager.AddActionHandler(lifetime, EditorStartNewLineBeforeAction.ACTION_ID, this, Func<_,_>(handleStartNewLineBeforePressed), isActionHandlerAvailable)
manager.AddActionHandler(lifetime, TextControlActions.ActionIds.Enter, this, handleEnter, isActionHandlerAvailable)
manager.AddActionHandler(lifetime, EditorStartNewLineBeforeAction.ACTION_ID, this, handleStartNewLineBeforePressed, isActionHandlerAvailable)
manager.AddActionHandler(lifetime, EditorStartNewLineAction.ACTION_ID, this, handleStartNewLinePressed, isActionHandlerAvailable)
manager.AddActionHandler(lifetime, TextControlActions.ActionIds.Backspace, this, Func<_,_>(this.HandleBackspacePressed), isActionHandlerAvailable)
manager.AddActionHandler(lifetime, TextControlActions.ActionIds.Tab, this, Func<_,_>(this.HandleTabPressed), isActionHandlerAvailable)
manager.AddActionHandler(lifetime, TextControlActions.ActionIds.TabLeft, this, Func<_,_>(this.HandleTabLeftPressed), isActionHandlerAvailable)
manager.AddTypingHandler(lifetime, ' ', this, Func<_,_>(handleSpace), isTypingHandlerAvailable)
manager.AddTypingHandler(lifetime, ' ', this, handleSpace, isTypingHandlerAvailable)

manager.AddTypingHandler(lifetime, '\'', this, Func<_,_>(this.HandleSingleQuoteTyped), isTypingHandlerAvailable)
manager.AddTypingHandler(lifetime, '"', this, Func<_,_>(this.HandleQuoteTyped), isSmartParensHandlerAvailable)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.jetbrains.rider.plugins.fsharp.test.cases.typingAssist

import com.intellij.openapi.actionSystem.IdeActions
import com.jetbrains.rider.test.annotations.Feature
import com.jetbrains.rider.test.annotations.Subsystem
import com.jetbrains.rider.test.annotations.TestEnvironment
import com.jetbrains.rider.test.base.PatchEngineEditorTestBase
import com.jetbrains.rider.test.base.PatchEngineEditorTestMode
import com.jetbrains.rider.test.env.enums.SdkVersion
import com.jetbrains.rider.test.reporting.SubsystemConstants
import org.testng.annotations.DataProvider
import org.testng.annotations.Test

abstract class FSharpTypingAssistPatchEngineTest(mode: PatchEngineEditorTestMode) : PatchEngineEditorTestBase(mode) {
override val checkTextControls = false
override val testSolution = "CoreConsoleApp"

@DataProvider(name = "simpleCases")
fun simpleCases() = arrayOf(
arrayOf("emptyFile"),
arrayOf("docComment"),
arrayOf("indent1"),
arrayOf("indent2"),
arrayOf("removeSelection1"),
arrayOf("removeSelection2"),
arrayOf("trailingSpace")
)

@Test(dataProvider = "simpleCases")
fun testStartNewLine(caseName: String) {
dumpOpenedEditorFacade("Program.fs", "Program.fs") {
typeOrCallAction(IdeActions.ACTION_EDITOR_START_NEW_LINE)
}
}

@Test
fun testStartNewLineUndo() {
dumpOpenedEditorFacade("Program.fs", "Program.fs") {
typeOrCallAction(IdeActions.ACTION_EDITOR_START_NEW_LINE)
undo()
}
}
}

@Test
@Subsystem(SubsystemConstants.TYPING_ASSIST)
@Feature("Typing Assist")
@TestEnvironment(sdkVersion = SdkVersion.LATEST_STABLE)
class FSharpTypingAssistPatchEngineSpeculativeRebaseProhibitedTest :
FSharpTypingAssistPatchEngineTest(PatchEngineEditorTestMode.SpeculativeRebaseProhibited)

@Test
@Subsystem(SubsystemConstants.TYPING_ASSIST)
@Feature("Typing Assist")
@TestEnvironment(sdkVersion = SdkVersion.LATEST_STABLE)
class FSharpTypingAssistPatchEngineSpeculativeAndForceRebaseTest :
FSharpTypingAssistPatchEngineTest(PatchEngineEditorTestMode.SpeculativeAndForceRebase)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let <selstart>x<selend> =
5
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let <selstart>x<selend> =
5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// It's x
/// <caret>
let x = 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// It'<caret>s x
let x = 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

<caret>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<caret>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let x =
<caret>
5
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let <caret>x =
5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let x =
5
<caret>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let x =
<caret>5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let =
<caret>
5
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let <selstart>x<selend> =
5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let x
<caret>
5
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let x <selstart>=<selend>
5
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let x =
<caret>
5
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let <caret>x =
5
Loading