-
Notifications
You must be signed in to change notification settings - Fork 135
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
Mishandling of hidden files & emacs backup files #1067
Comments
Hi @jleechpe I don't see how the OS could be the factor here. I am willing to guess it's more of a race condition somewhere. The initial log you shared would suggest that it happens even on a smaller config, but I have a reason to believe that there are some other configs (which you omitted from the comment), which the LS does still have to parse. I'm not implying they are the trigger of the bug, but it makes it unfortunately harder to reproduce the bug by just following the steps you outlined. Completion of resource types will not work without either Can you share more about the folder, or confirm that you were able to reproduce this with a single file in any other way? btw. if you wish to share the logs more privately, you can do so via email at |
Alternatively @arcsteveio would you be able to share the whole |
The only reason I'm suspecting it's OS related (although Mac + Linux) is that I use the exact same Emacs config on a Windows machine and have 0 issues with I did have additional provider config I forgot to include terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.0"
}
}
}
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
} GIF of reproducible steps to trigger the error on Archlinux (same steps but removed all my emacs config and terraform config for caching providers as well as anything else that might affect) using a freshly created user profile with the bare minimum to start emacs and load terraform-ls for a file.
|
Sure, I can share the main.tf file. I have no other variable files. It's 30 lines so I'll paste it in the window. provider "aws" {
region = "us-east-1"
}
data "aws_subnet" "mgmt" {
id = "subnet-0d7cf1345bb5add54"
}
data "aws_security_group" "mgmt_sg" {
id = "sg-0f548d25b5df4479b"
}
resource "aws_instance" "scratch" {
ami = "ami-05874fa9befd5c838"
subnet_id = data.aws_subnet.mgmt.id
iam_instance_profile = "AmazonSSMRoleForInstancesQuickSetup"
instance_type = "t3.micro"
key_name = "devops_demo_key"
security_groups = [data.aws_security_group.mgmt_sg.id]
tags = {
Name = "some-name"
ab_deploy_method = "terraform"
ab_deploy_owner = "sopalenski"
ab_deploy_env = "dev"
}
}
output "instance_id" {
value = aws_instance.scratch.id
} Happy to share more if it will help. |
I see that others have already given terraform files, so I would not share one more example (But do let me know, I can easily create one). Note that I have been able to trivially reproduce this in my Linux system (NixOS) in any of the terraform based projects. |
I'm able to reproduce the issue on Linux and macOS. The backup file created by emacs seems to trigger the error. When you open a
I cannot reproduce the issue starting with a clean directory containing only a Taking things one step further, one can force/reproduce the error by creating an invalid symlink:
That will break the parsing for the module and all language server requests like completion or hover will fail with the same error:
I think we should update the module parsing to ignore inaccessible files and continue parsing. |
I'm guessing the reason the issue doesn't show up on Windows is that it handles those symlinks differently under the hood? |
Thank you for debugging this one @dbanck ! I got caught up in this
It appears that emacs is effectively the trigger which creates the symlink, which of course other IDEs which run the LS can pick up as well once it is created and surface the same problem, but the other IDEs do not create these symlinks, which explains why this isn't reproducible without emacs. For context, this is likely related to the following issues/PRs around handling of hidden files:
I'd like to take a moment to think (again) about how we handle hidden files and the consequences of those decisions. AFAIK people do use symlinks which lead to genuinely parsable files, so we cannot just ignore symlinks entirely. Ignoring hidden files effectively means reverting #972 I also want to check how this affects hidden One possible solution would be treating such hidden files as more isolated individual files, such that they don't get parsed automatically with the rest of all cc @chriswacker |
Would disabling backup files (or writing them somewhere else) be a workaround? |
I'm not an emacs user, but if it's possible to move or disable the backup files, this should mitigate the problem. |
My default configuration does have a different location for backup files but that doesn't fix the issue:
I guess I can disable the creation of backup files, but that's something I would like to avoid. |
Can you ensure that there are no hidden files left over from emacs inside your project directory? Furthermore, I can take a look at your LS output log to see if there are any references to unreadable files. |
I've been following along with this as I have the exact same issue, but have just made a potentially useful discovery and a bit of a work around. So, emacs (depending on your config) is potentially creating several hidden files for slightly different purposes. Let's say you have a "main.tf" file, you might get I successfully moved the undo tree files to a different directory, using a config snippet like @psibi mentioned above, and made sure there were no old undo-tree files lying around, but still got the same issue occurring. I then added another bit of config like:
which disables the second hidden file ever being created, and now terraform ls seems happy again. These lockfiles cannot be stored in a different place so this seems to be the only valid workaround. I would prefer not to disable them as i find them quite useful (I use syncthing to sync certain files between machines, and these lockfiles let me know if I have a certain file already open on another machine with unsaved changes) |
Actually, updating further on this, there is now a variable in emacs 28, lock-file-name-transforms that does indeed allow you to change what this file gets called, and therefore where it lives, so you could use this to avoid these files in the working directory (see: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=31908) |
As a temporary workaround I have switched to 0.28.1 which I can confirm works fine. I also volunteer to test out any PR's which will help in resolving this issue. |
I can confirm that on emacs, |
I also get this problem on emacs 30.0.50 built from source. Not sure why the lsp is trying to read these files, but it sure is annoying! |
emacs+eglot with terraform-lsp works fine, whereas terraform-ls 0.30.2 still crashes on startup. disabling lockfiles didnt help. |
@cmdcelp Probably you want to open a different issue as this issue is about mis handling of hidden files in emacs ? Also, for me terraform-ls 0.30.2 seems to be working well with emacs + lsp-mode. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Server Version
0.29.0
0.29.1
0.29.2
Terraform Version
Client Version
Terraform Configuration Files
[|]
is cursorLog Output
Shows successful completion right after initializing then error on subsequent (after file is modified):
https://gist.github.com/jleechpe/3c449eab5885fc9149c5fa9a28d95261
Expected Behavior
Completions to populate
Actual Behavior
Emacs LSP-mode responds with "cannot find file: main.tf"
Emacs Eglot responds with json-rpc error
"main.tf: file not found"
Steps to Reproduce
LSP-Mode
Eglot
terraform-ls serve -log-file ~/tmp/tflog/log
)"main.tf: file not found"
Manually downloaded
terraform-ls
versions 0.29.2, 0.29.1, 0.29.0, 0.28.1 and tested with eglot:Connect using:
~/downloads/terraform-ls/<version>/terraform-ls serve
-> 0.29.x all error. 0.28.1 behaves as expected.Tested on Windows with Emacs 29.0.50, Terraform 1.2.9 and terraform-ls 0.29.2 -> No issues
Tested on Windows with VSCode -> No issues
Tested on Archlinux with VSCode -> Same issue as in Emacs (worked on initial test but multiple tests since have the same issue as Emacs)
I was able once or twice to get terraform-ls 0.29.2 to work in Emacs after stopping/restarting the server multiple (10+) times, but this was inconsistent and I could not determine what made it start working.
Also see: emacs-lsp/lsp-mode#3713 (issue on MacOS as well)
Edit: VSCode does not work on subsequent tests
The text was updated successfully, but these errors were encountered: