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

Simplify project resolution algorithm #839

Merged
merged 5 commits into from
Jan 21, 2023
Merged

Conversation

pfoerster
Copy link
Member

The goal of this PR is to simplify the algorithm used to determine the project files and the dependency graph:

  • Use the directory of the main TeX file as root directory (= compile directory)
  • Allow setting the root directory using a .texlabroot/texlabroot marker file
  • Tectonic.toml keeps overriding the root directory (if found)
  • .latexmkrc and .chktexrc files and the .git directory are no longer used to determine the root directory
  • Remove texlab.rootDirectory in favor of the texlabroot marker file

Fixes #826.

@leon-richardt
Copy link

leon-richardt commented Jan 19, 2023

I tested this branch (0d85e20 to be exact) with the project structure described in #838. When using an explicit texlabroot/.texlabroot file, the behavior is as described 👍
I also tested behavior without a texlabroot file in which case TexLab reports a Build Failure which seems to be caused by latexmk not being started correctly:

Log for 0d85e20 without any `texlabroot`

[Note:] I removed the contents of document.tex as I cannot share them publicly.

DEBUG - < {"method":"initialize","params":{"workspaceFolders":[{"uri":"file:\/\/\/home\/leon\/meeting-notes","name":"\/home\/leon\/meeting-notes"}],"trace":"off","capabilities":{"workspace":{"workspaceFolders":true,"symbol":{"dynamicRegistration":false,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalWorkspaceSymbolSupport":true},"configuration":true,"workspaceEdit":{"resourceOperations":["rename","create","delete"]},"applyEdit":true},"callHierarchy":{"dynamicRegistration":false},"textDocument":{"documentHighlight":{"dynamicRegistration":false},"references":{"dynamicRegistration":false},"signatureHelp":{"dynamicRegistration":false,"signatureInformation":{"parameterInformation":{"labelOffsetSupport":true},"activeParameterSupport":true,"documentationFormat":["markdown","plaintext"]}},"definition":{"linkSupport":true},"codeAction":{"dataSupport":true,"isPreferredSupport":true,"dynamicRegistration":false,"resolveSupport":{"properties":["edit"]},"codeActionLiteralSupport":{"codeActionKind":{"valueSet":["","Empty","QuickFix","Refactor","RefactorExtract","RefactorInline","RefactorRewrite","Source","SourceOrganizeImports","quickfix","refactor","refactor.extract","refactor.inline","refactor.rewrite","source","source.organizeImports"]}}},"declaration":{"linkSupport":true},"typeDefinition":{"linkSupport":true},"publishDiagnostics":{"tagSupport":{"valueSet":[1,2]},"relatedInformation":true},"implementation":{"linkSupport":true},"completion":{"insertTextMode":1,"completionItem":{"deprecatedSupport":true,"preselectSupport":true,"snippetSupport":true,"resolveSupport":{"properties":["documentation","detail","additionalTextEdits"]},"tagSupport":{"valueSet":[1]},"documentationFormat":["markdown","plaintext"],"labelDetailsSupport":true,"insertTextModeSupport":{"valueSet":[1,2]},"insertReplaceSupport":true,"commitCharactersSupport":true},"dynamicRegistration":false,"contextSupport":true,"completionItemKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]},"completionList":{"itemDefaults":["commitCharacters","editRange","insertTextFormat","insertTextMode","data"]}},"synchronization":{"dynamicRegistration":false,"didSave":true,"willSaveWaitUntil":false,"willSave":false},"documentSymbol":{"dynamicRegistration":false,"symbolKind":{"valueSet":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"hierarchicalDocumentSymbolSupport":true},"hover":{"dynamicRegistration":false,"contentFormat":["markdown","plaintext"]},"rename":{"dynamicRegistration":false,"prepareSupport":true}},"offsetEncoding":["utf-16"],"window":{"showDocument":{"support":false},"workDoneProgress":true,"showMessage":{"messageActionItem":{"additionalPropertiesSupport":false}}}},"processId":8465,"initializationOptions":{},"rootUri":"file:\/\/\/home\/leon\/meeting-notes","rootPath":"\/home\/leon\/meeting-notes","clientInfo":{"name":"Neovim","version":"0.8.2"}},"jsonrpc":"2.0","id":1}
DEBUG - > {"jsonrpc":"2.0","id":1,"result":{"capabilities":{"completionProvider":{"resolveProvider":true,"triggerCharacters":["\\","{","}","@","/"," "]},"definitionProvider":true,"documentFormattingProvider":true,"documentHighlightProvider":true,"documentLinkProvider":{"resolveProvider":false},"documentSymbolProvider":true,"executeCommandProvider":{"commands":["texlab.cleanAuxiliary","texlab.cleanArtifacts"]},"foldingRangeProvider":true,"hoverProvider":true,"inlayHintProvider":true,"referencesProvider":true,"renameProvider":{"prepareProvider":true},"textDocumentSync":{"change":2,"openClose":true,"save":{"includeText":false}},"workspaceSymbolProvider":true},"serverInfo":{"name":"TexLab","version":"5.0.0"}}}
DEBUG - < {"method":"initialized","jsonrpc":"2.0","params":{}}
DEBUG - < {"method":"workspace\/didChangeConfiguration","jsonrpc":"2.0","params":{"settings":{"texlab":{"build":{"executable":"latexmk","forwardSearchAfter":false,"args":["-lualatex","-shell-escape","-file-line-error","-synctex=1","-interaction=nonstopmode","%f"],"onSave":true},"latexindent":{"modifyLineBreaks":false},"chktex":{"onEdit":false,"onOpenAndSave":true},"formatterLineLength":100,"forwardSearch":{"executable":"zathura","args":["--synctex-forward","%l:1:%f","%p"]},"latexFormatter":"latexindent","bibtexFormatter":"texlab","diagnosticsDelay":300,"auxDirectory":"."}}}}
DEBUG - < {"method":"workspace\/didChangeConfiguration","jsonrpc":"2.0","params":{"settings":{"texlab":{"build":{"executable":"latexmk","forwardSearchAfter":false,"args":["-lualatex","-shell-escape","-file-line-error","-synctex=1","-interaction=nonstopmode","%f"],"onSave":true},"latexindent":{"modifyLineBreaks":false},"chktex":{"onEdit":false,"onOpenAndSave":true},"formatterLineLength":100,"forwardSearch":{"executable":"zathura","args":["--synctex-forward","%l:1:%f","%p"]},"latexFormatter":"latexindent","bibtexFormatter":"texlab","diagnosticsDelay":300,"auxDirectory":"."}}}}
DEBUG - < {"method":"textDocument\/didOpen","jsonrpc":"2.0","params":{"textDocument":{"uri":"file:\/\/\/home\/leon\/meeting-notes\/tex-doc\/document.tex","text":"[REMOVED]","version":0,"languageId":"tex"}}}
DEBUG - > {"jsonrpc":"2.0","id":1,"method":"workspace/configuration","params":{"items":[{"section":"texlab"}]}}
DEBUG - > {"jsonrpc":"2.0","id":2,"method":"workspace/configuration","params":{"items":[{"section":"texlab"}]}}
DEBUG - > {"jsonrpc":"2.0","id":3,"method":"workspace/configuration","params":{"items":[{"section":"texlab"}]}}
DEBUG - Loading document /home/leon/meeting-notes/tex-doc/document.aux from disk...
DEBUG - < {"result":[{"build":{"executable":"latexmk","forwardSearchAfter":false,"args":["-lualatex","-shell-escape","-file-line-error","-synctex=1","-interaction=nonstopmode","%f"],"onSave":true},"latexindent":{"modifyLineBreaks":false},"chktex":{"onEdit":false,"onOpenAndSave":true},"formatterLineLength":100,"forwardSearch":{"executable":"zathura","args":["--synctex-forward","%l:1:%f","%p"]},"latexFormatter":"latexindent","bibtexFormatter":"texlab","diagnosticsDelay":300,"auxDirectory":"."}],"jsonrpc":"2.0","id":1}
DEBUG - Loading document /home/leon/meeting-notes/tex-doc/document.log from disk...
DEBUG - < {"result":[{"build":{"executable":"latexmk","forwardSearchAfter":false,"args":["-lualatex","-shell-escape","-file-line-error","-synctex=1","-interaction=nonstopmode","%f"],"onSave":true},"latexindent":{"modifyLineBreaks":false},"chktex":{"onEdit":false,"onOpenAndSave":true},"formatterLineLength":100,"forwardSearch":{"executable":"zathura","args":["--synctex-forward","%l:1:%f","%p"]},"latexFormatter":"latexindent","bibtexFormatter":"texlab","diagnosticsDelay":300,"auxDirectory":"."}],"jsonrpc":"2.0","id":2}
DEBUG - < {"result":[{"build":{"executable":"latexmk","forwardSearchAfter":false,"args":["-lualatex","-shell-escape","-file-line-error","-synctex=1","-interaction=nonstopmode","%f"],"onSave":true},"latexindent":{"modifyLineBreaks":false},"chktex":{"onEdit":false,"onOpenAndSave":true},"formatterLineLength":100,"forwardSearch":{"executable":"zathura","args":["--synctex-forward","%l:1:%f","%p"]},"latexFormatter":"latexindent","bibtexFormatter":"texlab","diagnosticsDelay":300,"auxDirectory":"."}],"jsonrpc":"2.0","id":3}
INFO - Detected distribution: Texlive
DEBUG - > {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[{"message":"Bad type area settings! The detected line width is about 41% larger than the heuristically estimated maximum limit of typographical good line width. You should e.g. decrease DIV, (increase fontsize) or change papersize.","range":{"end":{"character":0,"line":0},"start":{"character":0,"line":0}},"severity":2,"source":"latex-build"},{"message":"Label `eq:xxx' multiply defined.","range":{"end":{"character":0,"line":0},"start":{"character":0,"line":0}},"severity":2,"source":"latex-build"},{"message":"Label `eq:xxx' multiply defined.","range":{"end":{"character":0,"line":0},"start":{"character":0,"line":0}},"severity":2,"source":"latex-build"},{"message":"Label `eq:xxx' multiply defined.","range":{"end":{"character":0,"line":0},"start":{"character":0,"line":0}},"severity":2,"source":"latex-build"},{"message":"Label `eq:xxx' multiply defined.","range":{"end":{"character":0,"line":0},"start":{"character":0,"line":0}},"severity":2,"source":"latex-build"},{"message":"Label `eq:xxx' multiply defined.","range":{"end":{"character":0,"line":0},"start":{"character":0,"line":0}},"severity":2,"source":"latex-build"},{"message":"Label `eq:xxx' multiply defined.","range":{"end":{"character":0,"line":0},"start":{"character":0,"line":0}},"severity":2,"source":"latex-build"},{"message":"Label `eq:xxx' multiply defined.","range":{"end":{"character":0,"line":0},"start":{"character":0,"line":0}},"severity":2,"source":"latex-build"},{"message":"Label `eq:xxx' multiply defined.","range":{"end":{"character":0,"line":0},"start":{"character":0,"line":0}},"severity":2,"source":"latex-build"},{"message":"Label `eq:xxx' multiply defined.","range":{"end":{"character":0,"line":0},"start":{"character":0,"line":0}},"severity":2,"source":"latex-build"},{"message":"There were multiply-defined labels.","range":{"end":{"character":0,"line":0},"start":{"character":0,"line":0}},"severity":2,"source":"latex-build"}],"uri":"file:///home/leon/meeting-notes/tex-doc/document.tex"}}
DEBUG - > {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[],"uri":"file:///home/leon/meeting-notes/tex-doc/document.aux"}}
DEBUG - < {"method":"textDocument\/documentHighlight","params":{"position":{"line":0,"character":0},"textDocument":{"uri":"file:\/\/\/home\/leon\/meeting-notes\/tex-doc\/document.tex"}},"jsonrpc":"2.0","id":2}
DEBUG - > {"jsonrpc":"2.0","id":2,"result":[]}
DEBUG - < {"method":"textDocument\/documentHighlight","params":{"position":{"line":1,"character":0},"textDocument":{"uri":"file:\/\/\/home\/leon\/meeting-notes\/tex-doc\/document.tex"}},"jsonrpc":"2.0","id":3}
DEBUG - > {"jsonrpc":"2.0","id":3,"result":[]}
DEBUG - < {"method":"textDocument\/documentHighlight","params":{"position":{"line":323,"character":0},"textDocument":{"uri":"file:\/\/\/home\/leon\/meeting-notes\/tex-doc\/document.tex"}},"jsonrpc":"2.0","id":4}
DEBUG - > {"jsonrpc":"2.0","id":4,"result":[]}
DEBUG - < {"method":"textDocument\/documentHighlight","params":{"position":{"line":321,"character":0},"textDocument":{"uri":"file:\/\/\/home\/leon\/meeting-notes\/tex-doc\/document.tex"}},"jsonrpc":"2.0","id":5}
DEBUG - > {"jsonrpc":"2.0","id":5,"result":[]}
DEBUG - < {"method":"textDocument\/build","params":{"textDocument":{"uri":"file:\/\/\/home\/leon\/meeting-notes\/tex-doc\/document.tex"}},"jsonrpc":"2.0","id":6}
DEBUG - > {"jsonrpc":"2.0","id":4,"method":"window/workDoneProgress/create","params":{"token":1}}
DEBUG - < {"result":null,"jsonrpc":"2.0","id":4}
DEBUG - > {"jsonrpc":"2.0","method":"$/progress","params":{"token":1,"value":{"cancellable":false,"kind":"begin","message":"file:///home/leon/meeting-notes/tex-doc/document.tex","title":"Building"}}}
ERROR - Failed to spawn process: "latexmk"
DEBUG - > {"jsonrpc":"2.0","method":"$/progress","params":{"token":1,"value":{"kind":"end"}}}
DEBUG - > {"jsonrpc":"2.0","id":6,"result":{"status":2}}
DEBUG - < {"method":"shutdown","jsonrpc":"2.0","id":7}
DEBUG - > {"jsonrpc":"2.0","id":7,"result":null}
DEBUG - < {"method":"exit","jsonrpc":"2.0"}

In neovim, TexLab is configured as follows:

TexLab Configuration
    texlab = {
        cmd = {"/home/leon/Projects/texlab/target/release/texlab", "-vvvv", "--log-file", "/tmp/texlab.log"},
        settings = {
            texlab = {
                build = {
                    args = { "-lualatex", "-shell-escape", "-file-line-error", "-synctex=1", "-interaction=nonstopmode",
                        "%f" },
                    onSave = true,
                },
                chktex = { onOpenAndSave = true },
                formatterLineLength = 100,
                forwardSearch = { executable = 'zathura', args = { '--synctex-forward', '%l:1:%f', '%p' } },
            },
        },
        commands = {
            TexlabForwardSearch = {
                function()
                    local pos = vim.api.nvim_win_get_cursor(0)
                    local params = {
                        textDocument = { uri = vim.uri_from_bufnr(0) },
                        position = { line = pos[1] - 1, character = pos[2] },
                    }
                    lsp.buf_request(0, 'textDocument/forwardSearch', params, function(err, _, _, _)
                        if err then
                            error(tostring(err))
                        end
                    end)
                end,
                description = 'Run synctex forward search',
            },
        },
    },

@leon-richardt
Copy link

leon-richardt commented Jan 19, 2023

One more thing: Shouldn't the project discovery behavior be documented somewhere? Or are you intentionally holding off on documenting behavior until it is considered robust enough to make it into a major release?

@pfoerster pfoerster force-pushed the simplify-project-resolution branch from c436a74 to 45703b4 Compare January 19, 2023 19:51
@pfoerster
Copy link
Member Author

pfoerster commented Jan 19, 2023

@leon-richardt

I also tested behavior without a texlabroot file in which case TexLab reports a Build Failure which seems to be caused by latexmk not being started correctly:

Thanks for catching this one! Should be fixed now :)

One more thing: Shouldn't the project discovery behavior be documented somewhere? Or are you intentionally holding off on documenting behavior until it is considered robust enough to make into a major release?

Definitely! At the moment, most of the documentation is part of the Wiki and the project detection definitely deserves its own page now. I think that we should stick to this approach implemented with this PR because it is a lot easier for the user to reason about. I will write something up in the Wiki.

EDIT: https://github.com/latex-lsp/texlab/wiki/Project-Detection-(v6.0.0-or-later)

@leon-richardt
Copy link

leon-richardt commented Jan 20, 2023

I also tested behavior without a texlabroot file in which case TexLab reports a Build Failure which seems to be caused by latexmk not being started correctly:

Thanks for catching this one! Should be fixed now :)

Just tested again with 45703b4 and can confirm it is fixed indeed 👍

@pfoerster pfoerster merged commit 9cbc238 into master Jan 21, 2023
@pfoerster pfoerster deleted the simplify-project-resolution branch January 21, 2023 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFE: Improve rootDirectory detection
2 participants