LSP icon indicating copy to clipboard operation
LSP copied to clipboard

LSP's `rename` fails in a particular scenario.

Open UltraInstinct05 opened this issue 4 years ago • 4 comments

Describe the bug Apologies for the vague issue title but I am not sure what else to call it other than the above 🙂

It seems that LSP's rename feature can't handle a particular scenario, when doing a rename in a Prisma schema file. The scenario is detailed as follows.

To Reproduce

  1. Install the LSP-prisma package.
  2. Install the Prisma package.
  3. Create a schema.prisma file somewhere and paste the following
model Model {
  id Int @id
  role Role @default(A_VARIANT_WITH_UNDERSCORES)
}

enum Role {
  ADMIN
  MODERATOR
  A_VARIANT_WITH_UNDERSCORES
}
  1. Right click on A_VARIANT_WITH_UNDERSCORES and use LSP -> Rename. Type anything for the new name and press enter

Expected behavior It seems VS Code is able to properly rename it.

Actual Behavior ST's LSP package seems to fail with the following traceback in the console.

Traceback (most recent call last):
  File "C:\Sublime Text\Lib\python33\sublime_plugin.py", line 1488, in run_
    return self.run(edit, **args)
  File "C:\Users\DELL\AppData\Roaming\Sublime Text\Installed Packages\LSP.sublime-package\plugin/edit.py", line 38, in run
  File "C:\Sublime Text\Lib\python33\sublime.py", line 1493, in text_point_utf16
    return sublime_api.view_text_point_utf16(self.view_id, row, col_utf16, clamp_column)
OverflowError: int too big to convert

Screenshots

sublime_text

Environment (please complete the following information):

  • OS: Windows 11
  • Sublime Text version: 4129
  • LSP version: 1.16.1
  • Language servers used: https://github.com/prisma/language-tools/tree/main/packages/language-server

Additional context No changes are made in LSP-prisma.sublime-settings. It's just the default what is shipped.

UltraInstinct05 avatar Mar 17 '22 14:03 UltraInstinct05

I’m guessing this is the issue

https://github.com/prisma/language-tools/blob/9baa91308a6f1604f51e5fd86e8d63399bc9151d/packages/language-server/src/rename/renameUtil.ts#L186

rwols avatar Mar 17 '22 19:03 rwols

Number.MAX_VALUE is 1.79E+308.

Number.MAX_SAFE_INTEGER is 2^53 - 1.

2^53 - 1 is still too large for LSP's uinteger type, which has max value ~~2^32 - 1~~ 2^31 - 1.

rwols avatar Mar 17 '22 20:03 rwols

Here are the server logs:

:: --> LSP-prisma textDocument/rename(4): {'newName': 'A_VARIANT_WITH_UNDERSCORESd', 'workDoneToken': 'wd4', 'textDocument': {'uri': 'file:///home/predragnikolic/.config/sublime-text/Packages/LSP-prisma/hello.prisma'}, 'position': {'line': 8, 'character': 20}}
LSP-prisma: Enum value 'A_VARIANT_WITH_UNDERSCORES' was renamed to 'A_VARIANT_WITH_UNDERSCORESd'
:: <-  LSP-prisma window/logMessage: {'type': 4, 'message': "Enum value 'A_VARIANT_WITH_UNDERSCORES' was renamed to 'A_VARIANT_WITH_UNDERSCORESd'"}
:: <<< LSP-prisma 4: {'changes': {'file:///home/predragnikolic/.config/sublime-text/Packages/LSP-prisma/hello.prisma': [{'newText': 'A_VARIANT_WITH_UNDERSCORESd', 'range': {'start': {'line': 8, 'character': 2}, 'end': {'line': 8, 'character': 28}}}, {'newText': ' @map("A_VARIANT_WITH_UNDERSCORES")', 'range': {'start': {'line': 8, 'character': 1.7976931348623157e+308}, 'end': {'line': 8, 'character': 1.7976931348623157e+308}}}, {'newText': '@default(A_VARIANT_WITH_UNDERSCORESd)', 'range': {'start': {'line': 2, 'character': 12}, 'end': {'line': 2, 'character': 48}}}]}}

If we look closely the character number is big 'character': 1.7976931348623157e+308. Here is what the spec says:

If the character value is greater than the line length it defaults to the line length.

interface [Position](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#position) {
	/**
	 * Line position in a document (zero-based).
	 */
	line: [uinteger](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#uinteger);

	/**
	 * Character offset on a line in a document (zero-based). Assuming that
	 * the line is represented as a string, the `character` value represents
	 * the gap between the `character` and `character + 1`.
	 *
	 * If the character value is greater than the line length it defaults back
	 * to the line length.
	 */
	character: [uinteger](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#uinteger);
}

I tired the fix PR https://github.com/sublimelsp/LSP/pull/1952, it solves the "OverflowError: int too big to convert" error in the ST console, but I would say that the rename functionality doesn't work right on the server...

Given this example:

model Model {
  id Int @id
  role Role @default(A_VARIANT_WITH_UNDERSCORES)
}

enum Role {
  ADMIN
  MODERATOR
  A_VARIANT_WITH_UNDERSCORES
}

I renamed A_VARIANT_WITH_UNDERSCORES to A_VARIANT_WITH_UNDERSCORESd

And I ended up with this:

model Model {
  id Int @id
  role Role @default(A_VARIANT_WITH_UNDERSCORESd)
}

enum Role {
  ADMIN
  MODERATOR
 @A_VARIANT_WITH_UNDERSCORESdCORES")  A_VARIANT_WITH_UNDERSCORES
}

predragnikolic avatar Mar 17 '22 23:03 predragnikolic

Thanks for looking into it !

UltraInstinct05 avatar Mar 18 '22 05:03 UltraInstinct05

Can we close this as there is nothing that LSP can do to fix this?

predragnikolic avatar Aug 13 '22 20:08 predragnikolic

It’s actually fixed by some PR in the past by clamping the possible values. But the language server should respect the protocol as well.

rwols avatar Aug 13 '22 22:08 rwols

True, I will close this as the LSP client bug was fixed with https://github.com/sublimelsp/LSP/pull/1952

I cannot reproduce the reported issue anymore. output1

NOTE: The server rename functionality still doesn't work in some cases and I would suggest opening up issues on the server for those cases.

predragnikolic avatar Aug 19 '22 18:08 predragnikolic