James-Yu / LaTeX-Workshop

Boost LaTeX typesetting efficiency with preview, compile, autocomplete, colorize, and more.
MIT License
10.58k stars 527 forks source link

texDirs not working #1369

Closed memeplex closed 5 years ago

memeplex commented 5 years ago

Disable all the other extensions except for LaTeX Workshop, and check that you still see this issue. [Required]

You still see this issue?: Yes

Describe the bug [Required]

With this config:

    "latex-workshop.latex.texDirs": [
        "/home/carlos/Library/TeXMF/tex/latex"
    ],
    "latex-workshop.intellisense.package.enabled": true

And a custom.sty file inside the configured texDirs:

  1. LaTeX Workshop is not completing the package name on \usepackage
  2. Neither the commands defined there are being completed by intellisense.

To Reproduce

Steps to reproduce the behavior:

  1. Create the path /home/xxx/Library/TeXMF/tex/latex
  2. Add a custom.sty file there with some defined LaTeX commands.
  3. Create a new tex file and try to get completion of \usepackage{cust
  4. After importing the package, try to get completion of the commands defined there.

Expected behavior

In points 3 and 4 above completion should work.

Logs [Required]

LaTeX Workshop Output [Required] [23:54:52] Initializing LaTeX Workshop. [23:54:52] Creating LaTeX Workshop http and websocket server. [23:54:52] LaTeX Workshop initialized. [23:54:53] Server created on 127.0.0.1:40091 [23:54:54] Snippet data loaded. [23:54:54] LaTeX Workshop version: 6.5.1
Developer Tools Console [Required] Can't see anything suspicious here.

Desktop [Required]:

memeplex commented 5 years ago

Looking at the source code this functionality doesn't seem to support sty files (as announced in the tooltip shown by vscode) nor \usepackage (which doesn't seem to be documented anywhere). The situation is quite confusing.

Now:

  1. Am I right?
  2. In that case, why is usepackage of a sty unsupported? This is a common case of using a custom library.
memeplex commented 5 years ago

Renaming my file to .tex and using \input I now get:

[2019-05-10 00:43:06.212] [exthost] [error] [James-Yu.latex-workshop] provider FAILED
[2019-05-10 00:43:06.213] [exthost] [error] TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at assertPath (path.js:39:11)
    at Object.dirname (path.js:1268:5)
    at module.exports.t.Input.provide (/home/carlos/.vscode-oss/extensions/james-yu.latex-workshop-6.5.1/out/src/main.js:371:486471)
    at module.exports.t.Completer.completion (/home/carlos/.vscode-oss/extensions/james-yu.latex-workshop-6.5.1/out/src/main.js:371:469046)
    at module.exports.t.Completer.provideCompletionItems.Promise (/home/carlos/.vscode-oss/extensions/james-yu.latex-workshop-6.5.1/out/src/main.js:371:467612)
    at new Promise (<anonymous>)
    at module.exports.t.Completer.provideCompletionItems (/home/carlos/.vscode-oss/extensions/james-yu.latex-workshop-6.5.1/out/src/main.js:371:466841)
    at define.provideCompletionItems.a.asPromise (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:592:293)
    at t.asPromise.Promise (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:49:430)
    at new Promise (<anonymous>)
    at Object.t.asPromise (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:49:402)
    at L.provideCompletionItems (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:592:264)
    at define.$provideCompletionItems._withAdapter.e (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:606:685)
    at B._withAdapter (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:599:159)
    at B.$provideCompletionItems (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:606:663)
    at d._doInvokeHandler (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:622:11)
    at d._invokeHandler (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:621:716)
    at d._receiveRequest (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:620:341)
    at d._receiveOneMessage (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:619:141)
    at define.constructor._protocol.onMessage.e (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:617:400)
    at u.fire (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:44:708)
    at e (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:40:460)
    at u.fire (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:44:708)
    at a (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:172:467)
    at e (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:172:513)
    at u.fire (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:44:708)
    at y._receiveMessage (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:181:276)
    at define.constructor._socketDisposables.push._socketReader.onMessage.e (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:178:415)
    at u.fire (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:44:708)
    at f.acceptChunk (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:175:35)
    at define.constructor._register._socket.onData.e (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:174:410)
    at Socket.t (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:182:689)
    at Socket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:283:12)
    at readableAddChunk (_stream_readable.js:264:11)
    at Socket.Readable.push (_stream_readable.js:219:10)
    at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
memeplex commented 5 years ago

Ok, after some debugging I realized this was caused because no root file was detected. I'm not closing this because I still see a number of shortcomings:

  1. The documentation specifies that sty files are supported but AFAICS they aren't.
  2. I think they should be supported. After all, it's just a matter of extending the regex to match \usepackage commands and .sty extensions. It's not necessary to understand the entire texmf hierarchy, the path in texDirs could simply be the specific directory where the sty file resides.
  3. I spent about half an hour figuring out I don't have a root file. I'm coming from years of emacs and elisp coding with the expectation of using something with a different trade-off: maybe not as powerful nor extensible, but yet powerful enough and, mainly, that just works. Showing a "no project root" popup for the newcomer would be polite.
jlelong commented 5 years ago

I have just updated the documentation. To make it clear, we do not parse and will not parse packages to search for newcommands because their structure is far too complicated and they very often include other packages in turn. Instead we rely on .cwl files to list the commands provided by every standard package.

Personal macro files should be loaded using one of the commands from the \input family but not \usepackage because of the above restriction.

memeplex commented 5 years ago

@jlelong the documentation of the texDirs setting is still wrong after the last update:

List of directories where to look for extra input .tex/.sty files.

jlelong commented 5 years ago

Hum, it was fixed in af174e5 and is included in 7.0.0. Can you point me to the wrong description?

memeplex commented 5 years ago

Mmmm, vscode told me the package has been updated, I checked the changelog and indeed things like "use input defs in mathjax preview" were there, now I see the installed package version is not 7.0.0, and even if I check for updates the new version is not listed. Have you seen anything like that? Maybe a problem with mirrors? In any case, the popup announcing the upgrade was not asking but stating that the upgrade has been performed.

memeplex commented 5 years ago

Nevertheless, I uninstalled and reinstalled and it picked up 7.0.0, weird... Thanks anyway.

memeplex commented 5 years ago

No, it didn't. In the extensions list, after uninstalling, it says 7.0.0. But when I install the extension the version is 6.5.1.

memeplex commented 5 years ago

Could it be a problem with your packaging. In the marketplace I see:

Version | 7.0.0 |  
Last updated | 5/16/2019, 11:39:27 PM

But then the latest release in your github is 6.5.1: https://github.com/James-Yu/LaTeX-Workshop/releases

memeplex commented 5 years ago

Ok, this seems to be the problem:

Unable to install extension 'james-yu.latex-workshop' as it is not compatible with VS Code '1.33.1'.
Failed Installing Extensions: /home/carlos/Downloads/James-Yu.latex-workshop-7.0.0.vsix

Maybe you should add a warning to the release notes (maybe there is one and I don't know where to look at). It's strange that vscode hasn't been more informative regarding this, though.

jlelong commented 5 years ago

This is a side effect of PR #1357. You are right, we should say something about this in the README file.