Skip to content
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

Formatting no longer works #871

Closed
bvdmitri opened this issue Mar 23, 2023 · 6 comments
Closed

Formatting no longer works #871

bvdmitri opened this issue Mar 23, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@bvdmitri
Copy link

bvdmitri commented Mar 23, 2023

Not sure what happened, I didn't change my configuration or anything, but after my vacation I returned to my document and I cannot longer format it. I tried texlab@5.3.0 but it does now work either. texlab@5.3.0 works as expected.

My config:

------------------- Latex LS settings -----------------
-- requires brew install --cask mactex & the Skim application
-- Read the current directory's path
local pwdhandle = io.popen("pwd")
vim.b.pwd = pwdhandle:read()
pwdhandle:close()

-- Get the basename of the current directory's path
local wdhandle = io.popen(string.format("basename %s", vim.b.pwd))
vim.b.wd = wdhandle:read()
wdhandle:close()

vim.b.texlabwd = string.format("/tmp/texlab-latex/%s", vim.b.wd) 
vim.b.texlab_latexindent_config = string.format("%s/latexindent.yaml", vim.b.pwd)

-- Create texlab working directory if it does not exist
os.execute(string.format("mkdir -p %s", vim.b.texlabwd))

lspconfig.texlab.setup {
  on_attach = on_attach,
  log_level = vim.lsp.protocol.MessageType.Log,
  settings = {
    texlab = {
      auxDirectory = vim.b.texlabwd,
      build = {
        executable = "latexmk",
        args = { "-pdf", "-interaction=nonstopmode", "-synctex=1", string.format("-outdir=%s", vim.b.texlabwd), "%f" },
        onSave = true,
      },
      forwardSearch = {
        executable = "/Applications/Skim.app/Contents/SharedSupport/displayline",
        args = { "%l", "%p", "%f" }
      },
      latexindent = {
        ['local'] = vim.b.texlab_latexindent_config,
        modifyLineBreaks = true
      }
    }
  },
  capabilities = autocomplete
}

Debug log level shows that Neovim sends the formatting command to the client but nothing happens. It was working about two weeks ago.

[DEBUG][2023-03-23 13:48:33] .../lua/vim/lsp.lua:1381	"LSP[texlab]"	"client.request"	1	"textDocument/formatting"	{  options = {    insertSpaces = true,    tabSize = 2  },  textDocument = {    uri = "file:///Users/bvdmitri/Projects/Latex/phdthesis/contents/02-variational-inference/01-introduction.tex"  }}	<function 1>	42
[DEBUG][2023-03-23 13:48:33] .../vim/lsp/rpc.lua:285	"rpc.send"	{  id = 13,  jsonrpc = "2.0",  method = "textDocument/formatting",  params = {    options = {      insertSpaces = true,      tabSize = 2    },    textDocument = {      uri = "file:///Users/bvdmitri/Projects/Latex/phdthesis/contents/02-variational-inference/01-introduction.tex"    }  }}
[DEBUG][2023-03-23 13:48:33] .../vim/lsp/rpc.lua:388	"rpc.receive"	{  id = 13,  jsonrpc = "2.0"}
[DEBUG][2023-03-23 13:49:43] .../lua/vim/lsp.lua:1381	"LSP[texlab]"	"client.request"	1	"textDocument/formatting"	{  options = {    insertSpaces = true,    tabSize = 2  },  textDocument = {    uri = "file:///Users/bvdmitri/Projects/Latex/phdthesis/contents/02-variational-inference/01-introduction.tex"  }}	<function 1>	42
[DEBUG][2023-03-23 13:49:43] .../vim/lsp/rpc.lua:285	"rpc.send"	{  id = 14,  jsonrpc = "2.0",  method = "textDocument/formatting",  params = {    options = {      insertSpaces = true,      tabSize = 2    },    textDocument = {      uri = "file:///Users/bvdmitri/Projects/Latex/phdthesis/contents/02-variational-inference/01-introduction.tex"    }  }}
[DEBUG][2023-03-23 13:49:43] .../vim/lsp/rpc.lua:388	"rpc.receive"	{  id = 14,  jsonrpc = "2.0"}
@pfoerster
Copy link
Member

@bvdmitri Can you try creating a log file using texlab -vvvv --log-file=/tmp/texlab.log, please? It would be helpful to know if texlab actually calls latexindent or if there is some other problem. There should be a line like Running latexindent in folder <...> with args: <...> in the log.

@pfoerster pfoerster added the needs more info Issue requires more information from poster label Mar 24, 2023
@maikol-solis
Copy link

I have the same issue with lsp-mode in emacs

[Trace - 09:51:04 AM] Sending request 'textDocument/formatting - (29)'.
Params: {
  "textDocument": {
    "uri": "path/to/myfile.tex"
  },
  "options": {
    "tabSize": 4,
    "insertSpaces": true,
    "trimTrailingWhitespace": true,
    "insertFinalNewline": true,
    "trimFinalNewlines": true
  }
}


[Trace - 09:51:04 AM] Received response 'textDocument/formatting - (29)' in 0ms.
Result: null

Weirdly, the server does not have any capabilities activated

image

texlab --version
texlab 5.4.0

@bvdmitri
Copy link
Author

@pfoerster Sure, I can try to give more info and create a log file, but I couldn't understand (from the documentation available) how to pass extra arguments to texlab executable while running from the Neovim's LSP mode.

EDIT: Ok, I figured it out. I used the cmd field in the LSP configuration to change the default arguments. I get the following output for the format command:

DEBUG - < {"params":{"options":{"tabSize":2,"insertSpaces":true},"textDocument":{"uri":"file:\/\/\/Users\/bvdmitri\/Projects\/Latex\/phdthesis\/contents\/02-variational-inference\/01-introduction.tex"}},"method":"textDocument\/formatting","id":8,"jsonrpc":"2.0"}
DEBUG - > {"jsonrpc":"2.0","id":8,"result":null}

I can manually call the latexindent command with the same arguments and it works just fine. The problem seems indeed to be somewhere between texlab and neovim LSP interaction. Perhaps, it stopped working after I ran brew upgrade and :PackerSync, but I didn't change my configuration.

Extra outputs for the build command just in case:

DEBUG - < {"params":{"textDocument":{"uri":"file:\/\/\/Users\/bvdmitri\/Projects\/Latex\/phdthesis\/contents\/02-variational-inference\/01-introduction.tex"}},"method":"textDocument\/build","id":6,"jsonrpc":"2.0"}
DEBUG - > {"jsonrpc":"2.0","id":5,"method":"window/workDoneProgress/create","params":{"token":2}}
DEBUG - < {"result":null,"id":5,"jsonrpc":"2.0"}
DEBUG - > {"jsonrpc":"2.0","method":"$/progress","params":{"token":2,"value":{"cancellable":false,"kind":"begin","message":"file:///Users/bvdmitri/Projects/Latex/phdthesis/main.tex","title":"Building"}}}
DEBUG - > {"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Rc files read:","type":4}}
DEBUG - > {"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"  NONE","type":4}}
DEBUG - > {"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Latexmk: This is Latexmk, John Collins, 17 Mar. 2022. Version 4.77, version: 4.77.","type":4}}
DEBUG - > {"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Latexmk: Nothing to do for '/Users/bvdmitri/Projects/Latex/phdthesis/main.tex'.","type":4}}
DEBUG - > {"jsonrpc":"2.0","method":"window/logMessage","params":{"message":"Latexmk: All targets (/private/tmp/texlab-latex/phdthesis/main.pdf) are up-to-date","type":4}}
DEBUG - > {"jsonrpc":"2.0","method":"$/progress","params":{"token":2,"value":{"kind":"end"}}}
DEBUG - > {"jsonrpc":"2.0","id":6,"result":{"status":0}}

and for the search command:

DEBUG - < {"params":{"position":{"character":1,"line":0},"textDocument":{"uri":"file:\/\/\/Users\/bvdmitri\/Projects\/Latex\/phdthesis\/contents\/02-variational-inference\/01-introduction.tex"}},"method":"textDocument\/forwardSearch","id":7,"jsonrpc":"2.0"}
DEBUG - Executing forward search: /Applications/Skim.app/Contents/SharedSupport/displayline ["1", "/tmp/texlab-latex/phdthesis/main.pdf", "/Users/bvdmitri/Projects/Latex/phdthesis/contents/02-variational-inference/01-introduction.tex"]
DEBUG - > {"jsonrpc":"2.0","id":7,"result":{"status":0}}

@bvdmitri
Copy link
Author

bvdmitri commented Mar 26, 2023

I do not get the Running latexindent in folder <...> with args: <...> line in my logs.

→ latexindent -v
3.16, 2022-03-13

EDIT: I have updated my tex installation and have the

→ latexindent -v
3.20.3, 2023-02-19

but that did not help to fix the issue

@bvdmitri
Copy link
Author

@pfoerster I did try again different version from the releases page and found out that 5.3.0 version works as expected and only 5.4.0 does not respond to the formatting request properly. I tried 5.3.0 before opennng the issue and thought it didn't work, but I must have not configured the environment properly.

So:

  • 5.3.0 formatting works
  • 5.4.0 formatting is broken

For 5.3.0 I also get the Running latexindent in folder <...> with args: <...> line in my logs.

pfoerster added a commit that referenced this issue Mar 26, 2023
@pfoerster pfoerster added bug Something isn't working and removed needs more info Issue requires more information from poster labels Mar 26, 2023
@pfoerster
Copy link
Member

Thanks for the logs! This bug should be fixed with v5.4.1.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Apr 27, 2023
## [5.5.0] - 2023-04-16

### Added

- Allow optionally passing cursor position to `textDocument/build` request for use in forward search after building.
  Previously, the server had to guess the cursor position ([#475](latex-lsp/texlab#475))
- Add experimental `texlab.experimental.citationCommands` setting to allow extending the list of citation commands
  ([#832](latex-lsp/texlab#832))
- Add support for escaping placeholders in build arguments similar to forward search
- Allow configuring completion matching algorithm ([#872](latex-lsp/texlab#872))

### Fixed

- Fix regression introduced in `v5.4.2` involving `texlab.cleanArtifacts` command.

## [5.4.2] - 2023-04-11

### Fixed

- Fix memory leak when editing documents over a long time ([#856](latex-lsp/texlab#856))
- Fix parsing parentheses in file paths ([#874](latex-lsp/texlab#874))

## [5.4.1] - 2023-03-26

### Fixed

- Do not return symbols with empty names (e. g. sections without name) ([#870](latex-lsp/texlab#870))
- Repair `textDocument/formatting` request ([#871](latex-lsp/texlab#871))

## [5.4.0] - 2023-03-12

### Added

- Add experimental settings to allow extending the list of special environments:
  - `texlab.experimental.mathEnvironments`
  - `texlab.experimental.enumEnvironments`
  - `texlab.experimental.verbatimEnvironments`
- Add `texlab.changeEnvironment` workspace command ([#849](latex-lsp/texlab#849))
- Add `texlab.showDependencyGraph` workspace command

### Changed

- Do not show caption or section names in label inlay hints ([#858](latex-lsp/texlab#858))
- Include more user-defined commands in command completion

### Fixed

- Parse nested `\iffalse` blocks correctly ([#853](latex-lsp/texlab#853))
- Parse commands with multi-byte characters correctly ([#857](latex-lsp/texlab#857))
- Fix checking whether a document can be a root file

## [5.3.0] - 2023-02-25

### Added

- Allow filtering `textDocument/documentSymbols` using regular expressions specified via
  `texlab.symbols.allowedPatterns` and `texlab.symbols.ignoredPatterns`
  ([#851](latex-lsp/texlab#851))

### Fixed

- Do not use percent-encoded path when searching for PDF files during forward search
  ([#848](latex-lsp/texlab#848))
- Always return an empty list of code actions instead of returning "method not found" ([#850](latex-lsp/texlab#850))

## [5.2.0] - 2023-01-29

### Added

- Include line numbers in build warnings when available ([#840](latex-lsp/texlab#840))
- Add `none` formatter to `texlab.latexFormatter` and `texlab.bibtexFormatter` options
  to allow disabling formatting ([#846](latex-lsp/texlab#846))

### Fixed

- Concatenate more than two lines of maximum length in build diagnostics ([#842](latex-lsp/texlab#842))
- Apply the correct range of references to labels when renaming ([#841](latex-lsp/texlab#841))
- Use `document` environment to detect root file instead of `\documentclass` ([#845](latex-lsp/texlab#845))

## [5.1.0] - 2023-01-21

### Added

- Allow manually overriding the root directory using a `texlabroot`/`.texlabroot` marker file.
  See the wiki for more information.
  ([#826](latex-lsp/texlab#826), [#838](latex-lsp/texlab#838))

### Deprecated

- Deprecate `texlab.rootDirectory` setting in favor of `.texlabroot` files

### Fixed

- Do not use `.git`, `.chktexrc`, `.latexmkrc` files/directories to determine the root directory
  ([#826](latex-lsp/texlab#826))
- Fix building documents without an explicit root directory ([#837](latex-lsp/texlab#837))

## [5.0.0] - 2022-12-29

### Changed

- _BREAKING_: `texlab.rootDirectory` is now used as the folder path from which the compiler is executed
  relative to the main document. By default it is equal to `"."`. For more information, please visit the wiki.
- Improve performance of completion by a huge margin due to a faster filtering method used internally
- Do not discover project files beyond the provided workspace folders
- Try to guess the root directory by checking for files such as `.latexmkrc` or `Tectonic.toml` if `texlab.rootDirectory` is not set

### Fixed

- Update positions of reported build diagnostics when editing the affected line
- Do not treat links to files as bidirectional by default. This prevents issues where `texlab` ends up compiling the wrong file
  in projects with shared files ([#806](latex-lsp/texlab#806), [#757](latex-lsp/texlab#757), [#679](latex-lsp/texlab#679))
- Fix coverage of directories which need to be watched for changes ([#502](latex-lsp/texlab#502), [#491](latex-lsp/texlab#491))
- Resolve links of the `import` package correctly
- Use `filterText` of completion items when filtering internally ([#829](latex-lsp/texlab#829))

## [4.3.2] - 2022-11-20

### Fixed

- Do not try to run the TeX engine on package files and fail the build instead ([#801](latex-lsp/texlab#801))
- Handle URIs with URL-encoded drive letters on Windows ([#802](latex-lsp/texlab#802))
- Parse BibTeX entries with unbalanced quotes correctly ([#809](latex-lsp/texlab#809))
- Provide completion for more acronym commands ([#813](latex-lsp/texlab#813))
- Fix parsing acronym definitions ([#813](latex-lsp/texlab#813))

## [4.3.1] - 2022-10-22

### Fixed

- Do not crash with a stack overflow when trying to load packages with many internal dependencies ([#793](latex-lsp/texlab#793))
- Normalize drive letters of all document URIs
- Fix parsing commands that take file paths as arguments ([#789](latex-lsp/texlab#789))
- Use the correct working directory and command line arguments when calling `latexindent` ([#645](latex-lsp/texlab#645))
- Fix publishing to CTAN

## [4.3.0] - 2022-09-25

### Added

- Add inlay hints for `\label{...}` ([#753](latex-lsp/texlab#753))

### Fixed

- Improve accuracy of the error locations reported by the TeX engine ([#738](latex-lsp/texlab#738))
- Reduce number of false positive errors reported by `texlab` ([#745](latex-lsp/texlab#745))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants