emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.78k stars 884 forks source link

project paths get messed up by lsp mode when saving/auto-adding import #4112

Open cam-narzt opened 1 year ago

cam-narzt commented 1 year ago

Thank you for the bug report

Bug description

relative import paths are getting mangled in my project's typescript files

eg from:

import { RegexCompositeType, RegexComposition } from './regex';

to

import { RegexCompositeType, RegexComposition } from '../../Developer/Rust/appname/app/javascript/components/app-component/regex';

which in addition to being an unwanted change, is not even a valid path, the ../../ at the beginning is not enough dirs up to get to the parent dir of the Developer dir (my home dir is the parent dir of Developer). The ../../ part of the path seems like the number of dirs to go up from emacs' backup dir to the $HOME dir.

also paths to emacs' backup files are being added to the tsconfig file's include list.

Steps to reproduce

create a typescript project import from one file to another with a relative import import foo from './bar' quit emacs start emacs with: emacs -q -nw lsp-start-plain.el add the following at the bottom of the file:

(custom-set-variables
 '(backup-by-copying-when-linked t)
 '(backup-directory-alist
   (list
    (cons ".*"
          (expand-file-name "~/.emacs.d/backup-files/"))))
)

M-x eval-buffer in the edited lsp-start-plain.el buffer

open a file in your project with a relative import add a space or comment or something into the file save file to trigger backup

Expected behavior

import path stays the same, tsconfig is not changed

Which Language Server did you use?

ts-ls

OS

MacOS

Error callstack

There is no error message from lsp-mode here's what the *Messages* buffer says:

LSP :: Connected to [ts-ls:10736 /Users/camdennarzt/Developer/Rust/appname].
Saving file /Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx...
LSP :: No formatting changes provided
LSP :: Applying 1 edits to `tsconfig.json' ...
Applying 1 edits to `tsconfig.json' ...done
LSP :: Applying 1 edits to `repetition.tsx' ...
Applying 1 edits to `repetition.tsx' ...done
Wrote /Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx
Quit
Formats have changed, recompiling...done
Updating buffer list...done
Mark set
Quit
C-x C-g is undefined
Quit
Mark set
Mark saved where search started
Auto-saving...done
Mark set
and the contents of the io log:
[Trace - 01:57:35 PM] Received notification '$/progress'.
Params: {
  "token": "660d352e-4beb-4629-8106-c8eb06738c25",
  "value": {
    "kind": "end"
  }
}

[Trace - 01:57:35 PM] Received response 'textDocument/inlayHint - (4)' in 1302ms.
Result: [
  {
    "position": {
      "line": 19,
      "character": 60
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 23,
      "character": 92
    },
    "label": ": RegexRepetition",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 24,
      "character": 16
    },
    "label": ": RegexRepetition",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 28,
      "character": 73
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 32,
      "character": 42
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 36,
      "character": 30
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 40,
      "character": 30
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 44,
      "character": 31
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 48,
      "character": 21
    },
    "label": ": any",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 49,
      "character": 38
    },
    "label": ": Event",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 50,
      "character": 34
    },
    "label": ": RegexRepetitionType",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 54,
      "character": 24
    },
    "label": ": any",
    "kind": 1,
    "paddingLeft": true
  }
]

[Trace - 01:57:35 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx",
  "diagnostics": []
}

[Trace - 01:57:36 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx",
  "diagnostics": []
}

[Trace - 01:57:36 PM] Sending request 'textDocument/codeAction - (6)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx"
  },
  "range": {
    "start": {
      "line": 0,
      "character": 0
    },
    "end": {
      "line": 0,
      "character": 0
    }
  },
  "context": {
    "diagnostics": []
  }
}

[Trace - 01:57:36 PM] Sending request 'textDocument/inlayHint - (7)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx"
  },
  "range": {
    "start": {
      "line": 0,
      "character": 0
    },
    "end": {
      "line": 54,
      "character": 0
    }
  }
}

[Trace - 01:57:36 PM] Sending request 'textDocument/documentHighlight - (8)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx"
  },
  "position": {
    "line": 0,
    "character": 0
  }
}

[Trace - 01:57:36 PM] Sending request 'textDocument/hover - (9)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx"
  },
  "position": {
    "line": 0,
    "character": 0
  }
}

[Trace - 01:57:36 PM] Received response 'textDocument/inlayHint - (7)' in 18ms.
Result: [
  {
    "position": {
      "line": 19,
      "character": 60
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 23,
      "character": 92
    },
    "label": ": RegexRepetition",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 24,
      "character": 16
    },
    "label": ": RegexRepetition",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 28,
      "character": 73
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 32,
      "character": 42
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 36,
      "character": 30
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 40,
      "character": 30
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 44,
      "character": 31
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 48,
      "character": 21
    },
    "label": ": any",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 49,
      "character": 38
    },
    "label": ": Event",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 50,
      "character": 34
    },
    "label": ": RegexRepetitionType",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 54,
      "character": 24
    },
    "label": ": any",
    "kind": 1,
    "paddingLeft": true
  }
]

[Trace - 01:57:36 PM] Received response 'textDocument/documentHighlight - (8)' in 23ms.
Result: []

[Trace - 01:57:36 PM] Received response 'textDocument/hover - (9)' in 23ms.
Result: {
  "contents": []
}

[Trace - 01:57:36 PM] Received response 'textDocument/codeAction - (6)' in 123ms.
Result: []

[Trace - 01:57:39 PM] Sending request 'textDocument/codeAction - (10)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx"
  },
  "range": {
    "start": {
      "line": 2,
      "character": 0
    },
    "end": {
      "line": 2,
      "character": 0
    }
  },
  "context": {
    "diagnostics": []
  }
}

[Trace - 01:57:39 PM] Sending request 'textDocument/inlayHint - (11)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx"
  },
  "range": {
    "start": {
      "line": 0,
      "character": 0
    },
    "end": {
      "line": 54,
      "character": 0
    }
  }
}

[Trace - 01:57:39 PM] Sending notification '$/cancelRequest'.
Params: {
  "id": 11
}

[Trace - 01:57:39 PM] Sending notification '$/cancelRequest'.
Params: {
  "id": 10
}

[Trace - 01:57:39 PM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx",
    "version": 1
  },
  "contentChanges": [
    {
      "range": {
        "start": {
          "line": 2,
          "character": 0
        },
        "end": {
          "line": 2,
          "character": 0
        }
      },
      "rangeLength": 0,
      "text": " "
    }
  ]
}

[Trace - 01:57:39 PM] Received response 'nil - (10)' in 0ms.
Result: []

[Trace - 01:57:39 PM] Received response 'nil - (11)' in 0ms.
Result: [
  {
    "position": {
      "line": 19,
      "character": 60
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 23,
      "character": 92
    },
    "label": ": RegexRepetition",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 24,
      "character": 16
    },
    "label": ": RegexRepetition",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 28,
      "character": 73
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 32,
      "character": 42
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 36,
      "character": 30
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 40,
      "character": 30
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 44,
      "character": 31
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 48,
      "character": 21
    },
    "label": ": any",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 49,
      "character": 38
    },
    "label": ": Event",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 50,
      "character": 34
    },
    "label": ": RegexRepetitionType",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 54,
      "character": 24
    },
    "label": ": any",
    "kind": 1,
    "paddingLeft": true
  }
]

[Trace - 01:57:39 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx",
  "diagnostics": []
}

[Trace - 01:57:39 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx",
  "diagnostics": []
}

[Trace - 01:57:39 PM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx",
    "version": 2
  },
  "contentChanges": [
    {
      "range": {
        "start": {
          "line": 2,
          "character": 0
        },
        "end": {
          "line": 2,
          "character": 1
        }
      },
      "rangeLength": 1,
      "text": ""
    }
  ]
}

[Trace - 01:57:39 PM] Sending request 'textDocument/rangeFormatting - (12)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx"
  },
  "options": {
    "tabSize": 4,
    "insertSpaces": true,
    "trimTrailingWhitespace": true,
    "insertFinalNewline": true,
    "trimFinalNewlines": true
  },
  "range": {
    "start": {
      "line": 0,
      "character": 0
    },
    "end": {
      "line": 81,
      "character": 0
    }
  }
}

[Trace - 01:57:39 PM] Received response 'textDocument/rangeFormatting - (12)' in 41ms.
Result: []

[Trace - 01:57:39 PM] Sending request 'workspace/willRenameFiles - (13)'.
Params: {
  "files": [
    {
      "oldUri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx",
      "newUri": "file:///Users/camdennarzt/.emacs.d/backup-files/%21Users%21camdennarzt%21Developer%21Rust%21appname%21app%21javascript%21components%21app-component%21repetition.tsx.~6~"
    }
  ]
}

[Trace - 01:57:39 PM] Received response 'workspace/willRenameFiles - (13)' in 58ms.
Result: {
  "changes": {
    "file:///Users/camdennarzt/Developer/Rust/appname/tsconfig.json": [
      {
        "range": {
          "start": {
            "line": 26,
            "character": 0
          },
          "end": {
            "line": 26,
            "character": 0
          }
        },
        "newText": ", \"../../../.emacs.d/backup-files/!Users!camdennarzt!Developer!Rust!appname!app!javascript!components!app-component!repetition.tsx.~6~\""
      }
    ],
    "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx": [
      {
        "range": {
          "start": {
            "line": 1,
            "character": 93
          },
          "end": {
            "line": 1,
            "character": 100
          }
        },
        "newText": "../../Developer/Rust/appname/app/javascript/components/app-component/regex"
      }
    ]
  }
}

[Trace - 01:57:40 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx",
  "diagnostics": []
}

[Trace - 01:57:41 PM] Sending notification 'textDocument/didChange'.
Params: {
  "textDocument": {
    "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx",
    "version": 3
  },
  "contentChanges": [
    {
      "range": {
        "start": {
          "line": 1,
          "character": 93
        },
        "end": {
          "line": 1,
          "character": 100
        }
      },
      "rangeLength": 7,
      "text": "../../Developer/Rust/appname/app/javascript/components/app-component/regex"
    }
  ]
}

[Trace - 01:57:41 PM] Sending notification 'textDocument/didSave'.
Params: {
  "textDocument": {
    "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx",
    "version": 3
  }
}

[Trace - 01:57:41 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx",
  "diagnostics": [
    {
      "range": {
        "start": {
          "line": 1,
          "character": 92
        },
        "end": {
          "line": 1,
          "character": 169
        }
      },
      "message": "Cannot find module '../../Developer/Rust/appname/app/javascript/components/app-component/regex' or its corresponding type declarations.",
      "severity": 1,
      "code": 2307,
      "source": "typescript",
      "tags": []
    },
    {
      "range": {
        "start": {
          "line": 50,
          "character": 33
        },
        "end": {
          "line": 50,
          "character": 34
        }
      },
      "message": "Parameter 'e' implicitly has an 'any' type.",
      "severity": 1,
      "code": 7006,
      "source": "typescript",
      "tags": []
    }
  ]
}

[Trace - 01:57:41 PM] Sending request 'textDocument/documentSymbol - (14)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx"
  }
}

[Trace - 01:57:41 PM] Sending request 'textDocument/codeAction - (15)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx"
  },
  "range": {
    "start": {
      "line": 2,
      "character": 0
    },
    "end": {
      "line": 2,
      "character": 0
    }
  },
  "context": {
    "diagnostics": []
  }
}

[Trace - 01:57:41 PM] Sending request 'textDocument/inlayHint - (16)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx"
  },
  "range": {
    "start": {
      "line": 0,
      "character": 0
    },
    "end": {
      "line": 54,
      "character": 0
    }
  }
}

[Trace - 01:57:41 PM] Received response 'textDocument/documentSymbol - (14)' in 9ms.
Result: [
  {
    "name": "Repetition",
    "detail": "",
    "kind": 5,
    "range": {
      "start": {
        "line": 3,
        "character": 0
      },
      "end": {
        "line": 80,
        "character": 1
      }
    },
    "selectionRange": {
      "start": {
        "line": 8,
        "character": 13
      },
      "end": {
        "line": 8,
        "character": 37
      }
    },
    "children": [
      {
        "name": "build",
        "detail": "",
        "kind": 6,
        "range": {
          "start": {
            "line": 23,
            "character": 4
          },
          "end": {
            "line": 30,
            "character": 5
          }
        },
        "selectionRange": {
          "start": {
            "line": 23,
            "character": 4
          },
          "end": {
            "line": 23,
            "character": 9
          }
        },
        "children": [
          {
            "name": "changekeys",
            "detail": "",
            "kind": 13,
            "range": {
              "start": {
                "line": 26,
                "character": 8
              },
              "end": {
                "line": 26,
                "character": 43
              }
            },
            "selectionRange": {
              "start": {
                "line": 26,
                "character": 13
              },
              "end": {
                "line": 26,
                "character": 23
              }
            },
            "children": []
          },
          {
            "name": "changetype",
            "detail": "",
            "kind": 13,
            "range": {
              "start": {
                "line": 25,
                "character": 8
              },
              "end": {
                "line": 25,
                "character": 40
              }
            },
            "selectionRange": {
              "start": {
                "line": 25,
                "character": 13
              },
              "end": {
                "line": 25,
                "character": 23
              }
            },
            "children": []
          },
          {
            "name": "changevals",
            "detail": "",
            "kind": 13,
            "range": {
              "start": {
                "line": 27,
                "character": 8
              },
              "end": {
                "line": 27,
                "character": 49
              }
            },
            "selectionRange": {
              "start": {
                "line": 27,
                "character": 13
              },
              "end": {
                "line": 27,
                "character": 23
              }
            },
            "children": []
          },
          {
            "name": "forEach() callback",
            "detail": "",
            "kind": 12,
            "range": {
              "start": {
                "line": 28,
                "character": 39
              },
              "end": {
                "line": 28,
                "character": 107
              }
            },
            "selectionRange": {
              "start": {
                "line": 28,
                "character": 39
              },
              "end": {
                "line": 28,
                "character": 107
              }
            },
            "children": []
          },
          {
            "name": "rr",
            "detail": "",
            "kind": 14,
            "range": {
              "start": {
                "line": 24,
                "character": 14
              },
              "end": {
                "line": 24,
                "character": 42
              }
            },
            "selectionRange": {
              "start": {
                "line": 24,
                "character": 14
              },
              "end": {
                "line": 24,
                "character": 16
              }
            },
            "children": []
          }
        ]
      },
      {
        "name": "emitRepitition",
        "detail": "",
        "kind": 6,
        "range": {
          "start": {
            "line": 19,
            "character": 4
          },
          "end": {
            "line": 21,
            "character": 5
          }
        },
        "selectionRange": {
          "start": {
            "line": 19,
            "character": 4
          },
          "end": {
            "line": 19,
            "character": 18
          }
        },
        "children": []
      },
      {
        "name": "greedy",
        "detail": "",
        "kind": 7,
        "range": {
          "start": {
            "line": 15,
            "character": 4
          },
          "end": {
            "line": 15,
            "character": 29
          }
        },
        "selectionRange": {
          "start": {
            "line": 15,
            "character": 13
          },
          "end": {
            "line": 15,
            "character": 19
          }
        },
        "children": []
      },
      {
        "name": "greedyChanged",
        "detail": "",
        "kind": 6,
        "range": {
          "start": {
            "line": 44,
            "character": 4
          },
          "end": {
            "line": 46,
            "character": 5
          }
        },
        "selectionRange": {
          "start": {
            "line": 44,
            "character": 4
          },
          "end": {
            "line": 44,
            "character": 17
          }
        },
        "children": [
          {
            "name": "greedy",
            "detail": "",
            "kind": 7,
            "range": {
              "start": {
                "line": 45,
                "character": 30
              },
              "end": {
                "line": 45,
                "character": 88
              }
            },
            "selectionRange": {
              "start": {
                "line": 45,
                "character": 30
              },
              "end": {
                "line": 45,
                "character": 36
              }
            },
            "children": []
          }
        ]
      },
      {
        "name": "handleRepetitionSelected",
        "detail": "",
        "kind": 6,
        "range": {
          "start": {
            "line": 32,
            "character": 4
          },
          "end": {
            "line": 34,
            "character": 5
          }
        },
        "selectionRange": {
          "start": {
            "line": 32,
            "character": 4
          },
          "end": {
            "line": 32,
            "character": 28
          }
        },
        "children": [
          {
            "name": "type",
            "detail": "",
            "kind": 7,
            "range": {
              "start": {
                "line": 33,
                "character": 30
              },
              "end": {
                "line": 33,
                "character": 87
              }
            },
            "selectionRange": {
              "start": {
                "line": 33,
                "character": 30
              },
              "end": {
                "line": 33,
                "character": 34
              }
            },
            "children": []
          }
        ]
      },
      {
        "name": "lower",
        "detail": "",
        "kind": 7,
        "range": {
          "start": {
            "line": 13,
            "character": 4
          },
          "end": {
            "line": 13,
            "character": 27
          }
        },
        "selectionRange": {
          "start": {
            "line": 13,
            "character": 13
          },
          "end": {
            "line": 13,
            "character": 18
          }
        },
        "children": []
      },
      {
        "name": "lowerChanged",
        "detail": "",
        "kind": 6,
        "range": {
          "start": {
            "line": 36,
            "character": 4
          },
          "end": {
            "line": 38,
            "character": 5
          }
        },
        "selectionRange": {
          "start": {
            "line": 36,
            "character": 4
          },
          "end": {
            "line": 36,
            "character": 16
          }
        },
        "children": [
          {
            "name": "bounds",
            "detail": "",
            "kind": 7,
            "range": {
              "start": {
                "line": 37,
                "character": 30
              },
              "end": {
                "line": 37,
                "character": 117
              }
            },
            "selectionRange": {
              "start": {
                "line": 37,
                "character": 30
              },
              "end": {
                "line": 37,
                "character": 36
              }
            },
            "children": []
          }
        ]
      },
      {
        "name": "regexUpdated",
        "detail": "",
        "kind": 7,
        "range": {
          "start": {
            "line": 17,
            "character": 4
          },
          "end": {
            "line": 17,
            "character": 57
          }
        },
        "selectionRange": {
          "start": {
            "line": 17,
            "character": 13
          },
          "end": {
            "line": 17,
            "character": 25
          }
        },
        "children": []
      },
      {
        "name": "render",
        "detail": "",
        "kind": 6,
        "range": {
          "start": {
            "line": 73,
            "character": 4
          },
          "end": {
            "line": 79,
            "character": 5
          }
        },
        "selectionRange": {
          "start": {
            "line": 73,
            "character": 4
          },
          "end": {
            "line": 73,
            "character": 10
          }
        },
        "children": []
      },
      {
        "name": "renderBoundsInputs",
        "detail": "",
        "kind": 6,
        "range": {
          "start": {
            "line": 54,
            "character": 4
          },
          "end": {
            "line": 64,
            "character": 5
          }
        },
        "selectionRange": {
          "start": {
            "line": 54,
            "character": 4
          },
          "end": {
            "line": 54,
            "character": 22
          }
        },
        "children": [
          {
            "name": "lower",
            "detail": "",
            "kind": 14,
            "range": {
              "start": {
                "line": 55,
                "character": 14
              },
              "end": {
                "line": 55,
                "character": 112
              }
            },
            "selectionRange": {
              "start": {
                "line": 55,
                "character": 14
              },
              "end": {
                "line": 55,
                "character": 19
              }
            },
            "children": []
          },
          {
            "name": "upper",
            "detail": "",
            "kind": 14,
            "range": {
              "start": {
                "line": 56,
                "character": 14
              },
              "end": {
                "line": 56,
                "character": 112
              }
            },
            "selectionRange": {
              "start": {
                "line": 56,
                "character": 14
              },
              "end": {
                "line": 56,
                "character": 19
              }
            },
            "children": []
          }
        ]
      },
      {
        "name": "renderGreedyInput",
        "detail": "",
        "kind": 6,
        "range": {
          "start": {
            "line": 66,
            "character": 4
          },
          "end": {
            "line": 71,
            "character": 5
          }
        },
        "selectionRange": {
          "start": {
            "line": 66,
            "character": 4
          },
          "end": {
            "line": 66,
            "character": 21
          }
        },
        "children": []
      },
      {
        "name": "renderTypeInput",
        "detail": "",
        "kind": 6,
        "range": {
          "start": {
            "line": 48,
            "character": 4
          },
          "end": {
            "line": 52,
            "character": 5
          }
        },
        "selectionRange": {
          "start": {
            "line": 48,
            "character": 4
          },
          "end": {
            "line": 48,
            "character": 19
          }
        },
        "children": [
          {
            "name": "RepetitionTypes.map() callback",
            "detail": "",
            "kind": 12,
            "range": {
              "start": {
                "line": 50,
                "character": 33
              },
              "end": {
                "line": 50,
                "character": 157
              }
            },
            "selectionRange": {
              "start": {
                "line": 50,
                "character": 33
              },
              "end": {
                "line": 50,
                "character": 157
              }
            },
            "children": []
          }
        ]
      },
      {
        "name": "repetition",
        "detail": "",
        "kind": 7,
        "range": {
          "start": {
            "line": 9,
            "character": 4
          },
          "end": {
            "line": 9,
            "character": 40
          }
        },
        "selectionRange": {
          "start": {
            "line": 9,
            "character": 12
          },
          "end": {
            "line": 9,
            "character": 22
          }
        },
        "children": []
      },
      {
        "name": "selected",
        "detail": "",
        "kind": 7,
        "range": {
          "start": {
            "line": 10,
            "character": 4
          },
          "end": {
            "line": 10,
            "character": 38
          }
        },
        "selectionRange": {
          "start": {
            "line": 10,
            "character": 12
          },
          "end": {
            "line": 10,
            "character": 20
          }
        },
        "children": []
      },
      {
        "name": "symbolic",
        "detail": "",
        "kind": 7,
        "range": {
          "start": {
            "line": 11,
            "character": 4
          },
          "end": {
            "line": 11,
            "character": 38
          }
        },
        "selectionRange": {
          "start": {
            "line": 11,
            "character": 12
          },
          "end": {
            "line": 11,
            "character": 20
          }
        },
        "children": []
      },
      {
        "name": "upper",
        "detail": "",
        "kind": 7,
        "range": {
          "start": {
            "line": 14,
            "character": 4
          },
          "end": {
            "line": 14,
            "character": 27
          }
        },
        "selectionRange": {
          "start": {
            "line": 14,
            "character": 13
          },
          "end": {
            "line": 14,
            "character": 18
          }
        },
        "children": []
      },
      {
        "name": "upperChanged",
        "detail": "",
        "kind": 6,
        "range": {
          "start": {
            "line": 40,
            "character": 4
          },
          "end": {
            "line": 42,
            "character": 5
          }
        },
        "selectionRange": {
          "start": {
            "line": 40,
            "character": 4
          },
          "end": {
            "line": 40,
            "character": 16
          }
        },
        "children": [
          {
            "name": "bounds",
            "detail": "",
            "kind": 7,
            "range": {
              "start": {
                "line": 41,
                "character": 30
              },
              "end": {
                "line": 41,
                "character": 117
              }
            },
            "selectionRange": {
              "start": {
                "line": 41,
                "character": 30
              },
              "end": {
                "line": 41,
                "character": 36
              }
            },
            "children": []
          }
        ]
      }
    ]
  }
]

[Trace - 01:57:41 PM] Received response 'textDocument/inlayHint - (16)' in 9ms.
Result: [
  {
    "position": {
      "line": 19,
      "character": 60
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 23,
      "character": 92
    },
    "label": ": any",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 24,
      "character": 16
    },
    "label": ": any",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 28,
      "character": 73
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 32,
      "character": 42
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 36,
      "character": 30
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 40,
      "character": 30
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 44,
      "character": 31
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 48,
      "character": 21
    },
    "label": ": any",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 49,
      "character": 38
    },
    "label": ": Event",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 50,
      "character": 34
    },
    "label": ": any",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 54,
      "character": 24
    },
    "label": ": any",
    "kind": 1,
    "paddingLeft": true
  }
]

[Trace - 01:57:41 PM] Received response 'textDocument/codeAction - (15)' in 11ms.
Result: []

[Trace - 01:57:43 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
  "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx",
  "diagnostics": [
    {
      "range": {
        "start": {
          "line": 1,
          "character": 92
        },
        "end": {
          "line": 1,
          "character": 169
        }
      },
      "message": "Cannot find module '../../Developer/Rust/appname/app/javascript/components/app-component/regex' or its corresponding type declarations.",
      "severity": 1,
      "code": 2307,
      "source": "typescript",
      "tags": []
    },
    {
      "range": {
        "start": {
          "line": 50,
          "character": 33
        },
        "end": {
          "line": 50,
          "character": 34
        }
      },
      "message": "Parameter 'e' implicitly has an 'any' type.",
      "severity": 1,
      "code": 7006,
      "source": "typescript",
      "tags": []
    }
  ]
}

[Trace - 01:57:53 PM] Sending request 'textDocument/inlayHint - (17)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx"
  },
  "range": {
    "start": {
      "line": 0,
      "character": 0
    },
    "end": {
      "line": 49,
      "character": 0
    }
  }
}

[Trace - 01:57:53 PM] Sending request 'textDocument/inlayHint - (18)'.
Params: {
  "textDocument": {
    "uri": "file:///Users/camdennarzt/Developer/Rust/appname/app/javascript/components/app-component/repetition.tsx"
  },
  "range": {
    "start": {
      "line": 0,
      "character": 0
    },
    "end": {
      "line": 49,
      "character": 0
    }
  }
}

[Trace - 01:57:53 PM] Received response 'textDocument/inlayHint - (17)' in 10ms.
Result: [
  {
    "position": {
      "line": 19,
      "character": 60
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 23,
      "character": 92
    },
    "label": ": any",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 24,
      "character": 16
    },
    "label": ": any",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 28,
      "character": 73
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 32,
      "character": 42
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 36,
      "character": 30
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 40,
      "character": 30
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 44,
      "character": 31
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 48,
      "character": 21
    },
    "label": ": any",
    "kind": 1,
    "paddingLeft": true
  }
]

[Trace - 01:57:53 PM] Received response 'textDocument/inlayHint - (18)' in 9ms.
Result: [
  {
    "position": {
      "line": 19,
      "character": 60
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 23,
      "character": 92
    },
    "label": ": any",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 24,
      "character": 16
    },
    "label": ": any",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 28,
      "character": 73
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 32,
      "character": 42
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 36,
      "character": 30
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 40,
      "character": 30
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 44,
      "character": 31
    },
    "label": ": void",
    "kind": 1,
    "paddingLeft": true
  },
  {
    "position": {
      "line": 48,
      "character": 21
    },
    "label": ": any",
    "kind": 1,
    "paddingLeft": true
  }
]

Anything else?

This only started happening recently probably after a component updated: lsp-mode, ts-ls, or some npm package.

Running lsp-start-plain from my emacs with my config loaded raises this error:

Debugger entered--Lisp error: (file-error "Read error" "Is a directory" "/Users/camdennarzt/.history")
  #<subr insert-file-contents>("~/.history")
  apply(#<subr insert-file-contents> "~/.history" nil)
  editorconfig--advice-insert-file-contents(#<subr insert-file-contents> "~/.history")
  apply(editorconfig--advice-insert-file-contents #<subr insert-file-contents> "~/.history")
  insert-file-contents("~/.history")
  comint-read-input-ring(t)
  shell-mode()
  shell-command("/usr/local/opt/emacs/bin/emacs -q -l /var/folders/..." #<buffer  *lsp-start-plain*> nil)
  async-shell-command("/usr/local/opt/emacs/bin/emacs -q -l /var/folders/..." #<buffer  *lsp-start-plain*>)
  lsp-start-plain()
  funcall-interactively(lsp-start-plain)
  call-interactively(lsp-start-plain record nil)
  command-execute(lsp-start-plain record)
  execute-extended-command(nil "lsp-start-plain" "lsp-start-p")
  funcall-interactively(execute-extended-command nil "lsp-start-plain" "lsp-start-p")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)

I have no idea why it's looking at ~/.history at all, that file is not at all part of my project.

matthemsteger commented 1 year ago

In case it helps, I was getting this issue on my linux environment, but not on my MacOS. I had a slight difference in my config.

On both configs I had

(setq backup-directory-alist '(("." . "~/.emacs.d/backups")))
(setq auto-save-file-name-transforms '((".*" "~/.emacs.d/backups/" t)))

On my MacOS emacs config I had ..

(setq backup-by-copying t)

While on linux, I did not set this.

Once I set backup-by-copying to t, the problem went away on linux. I am sure there is good reason to set (backup-by-copying-when-linked t) sometimes (or the other configurations), so I would say this could be a possible workaround, but not a permanent solution.

Im pretty sure I set this on MacOS because of this issue https://github.com/emacs-lsp/lsp-mode/issues/3516, which is likely related, but I didnt sync the change to my other configs.

ledbettj commented 9 months ago

I just updated lsp-mode for the first time in while and started running into this problem as well; the first time I save a buffer, the import paths across all open buffers are rewritten and tsconfig.json is modified to include the path to a tempfile;

import { User } from './contexts/User';
// becomes:
import { User } from '../home/john/Projects/foo/src/contexts/User';

import { App } from './App';
// becomes:
import { App } from "../../../../../tmp/!home!john!Projects!foo!src!App.tsx~"

and this path is added to the tsconfig.json file in the project root:

  "include": ["src", "../../../../../tmp/!home!john!Projects!foo!src!App.tsx~"],`

IO log is attached iolog.txt