unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dario Gjorgjevski <dario.gjorgjevski@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 72696@debbugs.gnu.org
Subject: bug#72696: Track-changes errors out when file is overwritten using Node.js's fs.writeFile (at least on macOS)
Date: Thu, 22 Aug 2024 13:19:39 +0200	[thread overview]
Message-ID: <CAJm4QYPyy3Em9HUWpvLeC8w0BLwbU2TyUeFEb+1S4y4GKaUGMQ@mail.gmail.com> (raw)
In-Reply-To: <jwvikvvgzna.fsf-monnier+emacs@gnu.org>

Hi, Stefan,

On Tue, Aug 20, 2024 at 2:15 PM Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>
> >> - Eglot errors out.  This should definitely not happen and seems like
> >>   a regression.  Restarting Eglot should definitely not be needed.
> >> Could you clarify what you mean by Eglot erroring out and why
> >> restarting it is necessary?
> > Eglot gets in a weird state and begins reporting erroneous data to the
> > LSP server.
>
> Can you give any further details?

Consider a Python file with the following contents (including a
trailing newline):

    from urllib import urlretrieve
    local_filename, headers = urlretrieve('http://python.org/')

Using the Pyright LSP server, Eglot correctly reports that:

    Pyright [reportAttributeAccessIssue]: "urlretrieve" is unknown import symbol

Now, rewrite the file using Node.js as instructed above so that its
contents become (again, including a trailing newline):

    from urllib.request import urlretrieve
    local_filename, headers = urlretrieve('http://python.org/')

Eglot now weirdly reports that:

    Pyright [reportMissingImports]: Import "urllib.request.request"
could not be resolved

Somehow it thinks that the ".request" part appears twice in a row.
Here is the relevant communication between Eglot and Pyright:

    [jsonrpc] e[13:00:21.956] --> textDocument/didOpen
    {
      "jsonrpc": "2.0",
      "method": "textDocument/didOpen",
      "params": {
        "textDocument": {
          "uri": "file:///Volumes/workplace/playground/test.py",
          "version": 0,
          "languageId": "python",
          "text": "from urllib import urlretrieve\nlocal_filename,
headers = urlretrieve('http://python.org/')\n"
        }
      }
    }

    [jsonrpc] e[13:00:22.617] <-- textDocument/publishDiagnostics
    {
      "jsonrpc": "2.0",
      "method": "textDocument/publishDiagnostics",
      "params": {
        "uri": "file:///Volumes/workplace/playground/test.py",
        "version": 0,
        "diagnostics": [
          {
            "range": {
              "start": {
                "line": 0,
                "character": 19
              },
              "end": {
                "line": 0,
                "character": 30
              }
            },
            "message": "\"urlretrieve\" is unknown import symbol",
            "severity": 1,
            "code": "reportAttributeAccessIssue",
            "source": "Pyright",
            "codeDescription": {
              "href":
"https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportAttributeAccessIssue"
            }
          }
        ]
      }
    }

    [jsonrpc] e[13:00:26.362] --> textDocument/didClose
    {
      "jsonrpc": "2.0",
      "method": "textDocument/didClose",
      "params": {
        "textDocument": {
          "uri": "file:///Volumes/workplace/playground/test.py"
        }
      }
    }

    [jsonrpc] e[13:00:26.364] --> textDocument/didOpen
    {
      "jsonrpc": "2.0",
      "method": "textDocument/didOpen",
      "params": {
        "textDocument": {
          "uri": "file:///Volumes/workplace/playground/test.py",
          "version": 0,
          "languageId": "python",
          "text": "from urllib.request import
urlretrieve\nlocal_filename, headers =
urlretrieve('http://python.org/')\n"
        }
      }
    }

    [jsonrpc] e[13:00:26.366] --> textDocument/didChange
    {
      "jsonrpc": "2.0",
      "method": "textDocument/didChange",
      "params": {
        "textDocument": {
          "uri": "file:///Volumes/workplace/playground/test.py",
          "version": 1
        },
        "contentChanges": [
          {
            "range": {
              "start": {
                "line": 0,
                "character": 11
              },
              "end": {
                "line": 0,
                "character": 11
              }
            },
            "rangeLength": 0,
            "text": ".request"
          }
        ]
      }
    }

    [jsonrpc] e[13:00:26.629] <-- textDocument/publishDiagnostics
    {
      "jsonrpc": "2.0",
      "method": "textDocument/publishDiagnostics",
      "params": {
        "uri": "file:///Volumes/workplace/playground/test.py",
        "version": 1,
        "diagnostics": [
          {
            "range": {
              "start": {
                "line": 0,
                "character": 5
              },
              "end": {
                "line": 0,
                "character": 27
              }
            },
            "message": "Import \"urllib.request.request\" could not be
resolved",
            "severity": 1,
            "code": "reportMissingImports",
            "source": "Pyright",
            "codeDescription": {
              "href":
"https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportMissingImports"
            }
          }
        ]
      }
    }

As far as I can see, the testDocument/didChange request should not be
there.  The rewrite seems to have triggered a textDocument/didClose
followed by a textDocument/didOpen, so the erroneous
textDocument/didChange ended up making the LSP server think the
".request" part appears twice in a row.

Best regards,
Dario





  reply	other threads:[~2024-08-22 11:19 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-18 10:58 bug#72696: Track-changes errors out when file is overwritten using Node.js's fs.writeFile (at least on macOS) Dario Gjorgjevski
2024-08-18 11:02 ` Eli Zaretskii
2024-08-18 16:10 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-08-18 20:36   ` Dario Gjorgjevski
2024-08-20 12:15     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-08-22 11:19       ` Dario Gjorgjevski [this message]
2024-08-22 11:27         ` Dario Gjorgjevski
2024-09-07  7:15           ` Eli Zaretskii
2024-09-08 23:06         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-18 22:02           ` Dario Gjorgjevski
2024-09-19  5:32             ` Eli Zaretskii
2024-09-19 12:58               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-19 21:47                 ` João Távora
2024-09-20  6:21                   ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJm4QYPyy3Em9HUWpvLeC8w0BLwbU2TyUeFEb+1S4y4GKaUGMQ@mail.gmail.com \
    --to=dario.gjorgjevski@gmail.com \
    --cc=72696@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).