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

Specify cursor position when creating new files #1546

Merged
merged 2 commits into from
Mar 27, 2020

Conversation

gabro
Copy link
Member

@gabro gabro commented Mar 26, 2020

Closes #1529

Previously we would set the cursor position at the beginning of the file when creating a new file. Now we place the cursor in a more convenient position, depending on the type of file.

Demo:
2020-03-23 17 49 31

import scala.meta.internal.metals.NewFileTemplate
import org.scalacheck.Gen
import org.scalacheck.Prop.forAll

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @olafurpg dogfooding the new scalacheck module 👇

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need Scalacheck here though? It's supposed to be used over a set of possible values and here it is just normal testing. I have never found a usage for property based testing and maybe it would be better to keep the tests consistent?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's supposed to be used over a set of possible values and here it is just normal testing

I'm using Scalacheck to test "all" possible positions of the cursor inside a (fixed) document.

Do we really need Scalacheck here though?

It's not strictly necessary, but it just gives me a little more confidence that the computation is not right by chance but it holds for "all" possible cursor positions.

That said, if you prefer we can remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using Scalacheck to test "all" possible positions of the cursor inside a (fixed) document.

I am totally blind and have not seen it. It's a perfectly valid scenario to use it in. 👍

@gabro gabro force-pushed the new-file-cursor branch 2 times, most recently from 2feb190 to 50bc72b Compare March 26, 2020 09:43
Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this feature! It will be much more comfortable to create new files now.

I am not sure about using Scalacheck here though.


class NewFileTemplateSuite extends BaseSuite with ScalaCheckSuite {

test("it requires exactly one cursor marker") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we stick to short names as in other suites?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, absolutely, I completely forgot. Fixed

import scala.meta.internal.metals.NewFileTemplate
import org.scalacheck.Gen
import org.scalacheck.Prop.forAll

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need Scalacheck here though? It's supposed to be used over a set of possible values and here it is just normal testing. I have never found a usage for property based testing and maybe it would be better to keep the tests consistent?

@gabro
Copy link
Member Author

gabro commented Mar 27, 2020

2020-03-27T08:11:21.6652922Z [error] ==> X tests.HoverLspSuite.basic-rambo  2.558s munit.FailException: D:\a\metals\metals\tests\unit\src\test\scala\tests\HoverLspSuite.scala:35 Obtained empty output!
2020-03-27T08:11:21.6653700Z [error] 34:      )
2020-03-27T08:11:21.6654013Z [error] 35:      _ <- server.assertHover(
2020-03-27T08:11:21.6654296Z [error] 36:        "a/src/main/scala/a/Main.scala",
2020-03-27T08:11:21.6654871Z [error]     at munit.Assertions.fail(Assertions.scala:178)

Unrelated flaky test (we should probably mark it as FlakyWindows)

Merging

@gabro gabro merged commit 06e844c into scalameta:master Mar 27, 2020
@gabro gabro deleted the new-file-cursor branch March 27, 2020 09:07
|case class Foo()
|""".stripMargin
val cursorOffsetGen = Gen.chooseNum(0, template.length)
forAll(cursorOffsetGen) { cursorOffset =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between forAll here and 0.to(template.length).foreach { .. }?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, good point: in this case just the number of iterations (100 with ScalaCheck). I can revert to just using a range

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 1.to(100) would be clearer and more consistent with the rest of the tests. Property based testing is more helpful when you can't tests all possible inputs.

@gabro gabro mentioned this pull request Mar 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move cursor to a more convenient location when creating a new file
3 participants