Git Product home page Git Product logo

Comments (11)

randy3k avatar randy3k commented on May 23, 2024

It is VSCode specific issue, but there is more going on here. The problem is, in range formatting, we always get the full lines of the selection.

range <- range(
start = position(line = line1, character = 0),
end = position(line = line2, character = ncodeunit(document$line(line2 + 1)))
)

When you paste "a" to "p", the text being formatted is

  colnames = c("a", "b", "c", "d", "e",
  "f", "g", "h", "i", "j", "k", "l",
  "m", "n", "o", "p")))

That's why we get an error.

The easiest fix is to catch the possible error of style_text since we cannot predict what will be passed to it.

Does VSCode really expect to run formatting for every paste? Sometime user may copy and paste an incomplete piece of code and obviously we don't want to format it.

from languageserver.

renkun-ken avatar renkun-ken commented on May 23, 2024

In vscode, there are formatOnType, formatOnPaste, and formatOnSave options. I think such formatting error can be suppressed unless debug mode is on.

from languageserver.

randy3k avatar randy3k commented on May 23, 2024

I believe that the error is suppressed when debug mode is off, isn't it?

from languageserver.

renkun-ken avatar renkun-ken commented on May 23, 2024

My debug mode is off but this still appears.

from languageserver.

randy3k avatar randy3k commented on May 23, 2024

Note that you will need to restart VSCode. You are right.

from languageserver.

randy3k avatar randy3k commented on May 23, 2024

The problem is more complicated when I thought.

foo <- function(
		x = 1,
		y = 2
	) {
	# body
}

If I paste z = 1 to replace y = 2. I got

foo <- function(
		x = 1,
		z <- 1
	) {
	# body
}

from languageserver.

randy3k avatar randy3k commented on May 23, 2024

I guess we need to check if the selection is from the beginning to the end of all the lines included.

from languageserver.

renkun-ken avatar renkun-ken commented on May 23, 2024

This example is caused by assignment operator fix, even if you select the full line, the formatting would make this happen, doesn't it?

from languageserver.

randy3k avatar randy3k commented on May 23, 2024

Yes, it would still be an issue. But at least it is not triggered all the times. A better solution is to check the scope of the selection. But it can be difficult in some situations.

from languageserver.

renkun-ken avatar renkun-ken commented on May 23, 2024

Maybe we can turn off operator replace by default?

from languageserver.

renkun-ken avatar renkun-ken commented on May 23, 2024

Use format selection in vscode will make this happen too.

Operator replacement is dangerous because <- and = are not always interchangeable. I think we should turn if off by default as an argument of style_text.

from languageserver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.