James-Yu / LaTeX-Workshop

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

\cref autocomplete not firing on second reference #3545

Closed alw-personal closed 1 year ago

alw-personal commented 1 year ago

Preliminary questions [Required]

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

You still see this issue?: Yes

Make sure to visit the wiki FAQ before filling an issue.

You visited the wiki?: Yes

If your issue is with compiling a document (not having to do with finding the root file of a project), check first that you can compile manually.

You can compile a TeX document manually?: N/A (but yes can compile)

Describe the bug [Required]

Autocomplete does not list references after first autocompleting first reference in \cref.

To Reproduce

Steps to reproduce the behavior:

  1. In a .tex file, create two or more labels, e.g., \label{thm:1} and \label{thm:2}
  2. Type \cref{th} to trigger autocomplete. Autocomplete shows thm:1 and thm:2.
  3. Pick thm:1 from list
  4. Continue typing ,th

Expected behavior

Autocomplete shows thm:1 and thm:2

Logs [Required]

LaTeX Workshop Output [Required]

[02:03:45] Initializing LaTeX Workshop.
[02:03:45] Extension root: /Users/USERNAME/.vscode/extensions/james-yu.latex-workshop-9.0.1
[02:03:45] $PATH: /Users/USERNAME/.pyenv/shims:/Users/USERNAME/Research/mosek/9.2/tools/platform/osx64x86/bin:/Users/USERNAME/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin
[02:03:45] $SHELL: /bin/bash
[02:03:45] $LANG: undefined
[02:03:45] $LC_ALL: undefined
[02:03:45] process.platform: darwin
[02:03:45] process.arch: x64
[02:03:45] vscode.env.appName: Visual Studio Code
[02:03:45] vscode.env.remoteName: undefined
[02:03:45] vscode.env.uiKind: 1
[02:03:45] Configuration for workspace: file:///Users/USERNAME/DIRECTORY
[02:03:45] editor.acceptSuggestionOnEnter: "on"
[02:03:45] latex-workshop.bind.enter.key: true
[02:03:45] latex-workshop.docker.enabled: false
[02:03:45] latex-workshop.docker.image.latex: ""
[02:03:45] latex-workshop.hover.preview.mathjax.extensions: []
[02:03:45] latex-workshop.intellisense.package.enabled: true
[02:03:45] latex-workshop.intellisense.update.aggressive.enabled: false
[02:03:45] latex-workshop.intellisense.update.delay: 1000
[02:03:45] latex-workshop.latex.autoBuild.run: "onSave"
[02:03:45] latex-workshop.latex.build.forceRecipeUsage: true
[02:03:45] latex-workshop.latex.outDir: "%DIR%/output"
[02:03:45] latex-workshop.latex.recipes: [
 {
  "name": "latexmk 🔃",
  "tools": [
   "latexmk"
  ]
 },
 {
  "name": "latexmk (latexmkrc)",
  "tools": [
   "latexmk_rconly"
  ]
 },
 {
  "name": "latexmk (lualatex)",
  "tools": [
   "lualatexmk"
  ]
 },
 {
  "name": "latexmk (xelatex)",
  "tools": [
   "xelatexmk"
  ]
 },
 {
  "name": "pdflatex ➞ bibtex ➞ pdflatex × 2",
  "tools": [
   "pdflatex",
   "bibtex",
   "pdflatex",
   "pdflatex"
  ]
 },
 {
  "name": "Compile Rnw files",
  "tools": [
   "rnw2tex",
   "latexmk"
  ]
 },
 {
  "name": "Compile Jnw files",
  "tools": [
   "jnw2tex",
   "latexmk"
  ]
 },
 {
  "name": "tectonic",
  "tools": [
   "tectonic"
  ]
 }
]
[02:03:45] latex-workshop.latex.tools: [
 {
  "name": "latexmk",
  "command": "latexmk",
  "args": [
   "-synctex=1",
   "-interaction=nonstopmode",
   "-file-line-error",
   "-pdf",
   "-outdir=%OUTDIR%",
   "%DOC%"
  ],
  "env": {}
 },
 {
  "name": "lualatexmk",
  "command": "latexmk",
  "args": [
   "-synctex=1",
   "-interaction=nonstopmode",
   "-file-line-error",
   "-lualatex",
   "-outdir=%OUTDIR%",
   "%DOC%"
  ],
  "env": {}
 },
 {
  "name": "xelatexmk",
  "command": "latexmk",
  "args": [
   "-synctex=1",
   "-interaction=nonstopmode",
   "-file-line-error",
   "-xelatex",
   "-outdir=%OUTDIR%",
   "%DOC%"
  ],
  "env": {}
 },
 {
  "name": "latexmk_rconly",
  "command": "latexmk",
  "args": [
   "%DOC%"
  ],
  "env": {}
 },
 {
  "name": "pdflatex",
  "command": "pdflatex",
  "args": [
   "-synctex=1",
   "-interaction=nonstopmode",
   "-file-line-error",
   "%DOC%"
  ],
  "env": {}
 },
 {
  "name": "bibtex",
  "command": "bibtex",
  "args": [
   "%DOCFILE%"
  ],
  "env": {}
 },
 {
  "name": "rnw2tex",
  "command": "Rscript",
  "args": [
   "-e",
   "knitr::opts_knit$set(concordance = TRUE); knitr::knit('%DOCFILE_EXT%')"
  ],
  "env": {}
 },
 {
  "name": "jnw2tex",
  "command": "julia",
  "args": [
   "-e",
   "using Weave; weave(\"%DOC_EXT%\", doctype=\"tex\")"
  ],
  "env": {}
 },
 {
  "name": "jnw2texmintex",
  "command": "julia",
  "args": [
   "-e",
   "using Weave; weave(\"%DOC_EXT%\", doctype=\"texminted\")"
  ],
  "env": {}
 },
 {
  "name": "tectonic",
  "command": "tectonic",
  "args": [
   "--synctex",
   "--keep-logs",
   "%DOC%.tex"
  ],
  "env": {}
 }
]
[02:03:45] latex-workshop.viewer.pdf.internal.keyboardEvent: "auto"
[02:03:45] Creating a new file watcher.
[02:03:45] watcherOptions: {"useFsEvents":false,"usePolling":false,"interval":300,"binaryInterval":1000,"awaitWriteFinish":{"stabilityThreshold":250}}
[02:03:45] Creating PDF file watcher.
[02:03:45] watcherOptions: {"useFsEvents":false,"usePolling":false,"interval":300,"binaryInterval":1000,"awaitWriteFinish":{}}
[02:03:45] Creating Bib file watcher.
[02:03:45] watcherOptions: {"useFsEvents":false,"usePolling":false,"interval":300,"binaryInterval":1000,"awaitWriteFinish":{"stabilityThreshold":250}}
[02:03:45] Set $LATEXWORKSHOP_DOCKER_LATEX: ""
[02:03:45] [Server] Creating LaTeX Workshop http and websocket server.
[02:03:46] LaTeX Workshop initialized.
[02:03:46] Trigger characters for intellisense of LaTeX documents: ["\\",",","{"]
[02:03:46] Bibtex format config: {"tab":"  ","case":"lowercase","left":"{","right":"}","trailingComma":false,"sort":["key"],"alignOnEqual":true,"sortFields":false,"fieldsOrder":[],"firstEntries":["string","xdata"]}
[02:03:46] Current workspace folders: ["file:///Users/USERNAME/DIRECTORY"]
[02:03:46] Found root file from active editor: /Users/USERNAME/DIRECTORY/FILE.tex
[02:03:46] Root file changed: from undefined to /Users/USERNAME/DIRECTORY/FILE.tex
[02:03:46] Start to find all dependencies.
[02:03:46] Root file languageId: latex
[02:03:46] Reset file watcher.
[02:03:46] Parsing a file and its subfiles: /Users/USERNAME/DIRECTORY/FILE.tex
[02:03:46] Parse fls file.
[02:03:46] Fls file found: /Users/USERNAME/DIRECTORY/FILE.fls
[02:03:46] Parse aux file: /Users/USERNAME/DIRECTORY/FILE.aux
[02:03:46] [Server] Server successfully started: {"address":"127.0.0.1","family":"IPv4","port":62120}
[02:03:46] Added to file watcher: /Users/USERNAME/DIRECTORY/FILE.tex
[02:03:46] Snippet data loaded.
[02:03:46] [Server] valdOrigin is http://127.0.0.1:62120
[02:03:46] Checking for duplicate labels: /Users/USERNAME/DIRECTORY/FILE.tex.
[02:03:48] Manager.fileWatcher.getWatched: {"/Users/USERNAME/DIRECTORY":["FILE.tex"]}
[02:03:48] Manager.filesWatched: ["/Users/USERNAME/DIRECTORY/FILE.tex"]
[02:03:48] BibWatcher.bibWatcher.getWatched: {}
[02:03:48] BibWatcher.bibsWatched: []
[02:03:48] PdfWatcher.pdfWatcher.getWatched: {}
[02:03:48] PdfWatcher.pdfsWatched: []
[02:03:48] PdfWatcher.watchedPdfVirtualUris: []
[02:03:48] PdfWatcher.ignoredPdfUris: []
[02:03:59] LOG command invoked: default

Developer Tools Console [Required]

TMScopeRegistry.ts:47 Overwriting grammar scope name to file mapping for scope text.tex.
Old grammar file: file:///Applications/Visual%20Studio%20Code.app/Contents/Resources/app/extensions/latex/syntaxes/TeX.tmLanguage.json.
New grammar file: file:///Users/USER/.vscode/extensions/james-yu.latex-workshop-9.0.1/syntax/TeX.tmLanguage.json
TMScopeRegistry.ts:47 Overwriting grammar scope name to file mapping for scope text.tex.latex.
Old grammar file: file:///Applications/Visual%20Studio%20Code.app/Contents/Resources/app/extensions/latex/syntaxes/LaTeX.tmLanguage.json.
New grammar file: file:///Users/USER/.vscode/extensions/james-yu.latex-workshop-9.0.1/syntax/LaTeX.tmLanguage.json
TMScopeRegistry.ts:47 Overwriting grammar scope name to file mapping for scope text.bibtex.
Old grammar file: file:///Applications/Visual%20Studio%20Code.app/Contents/Resources/app/extensions/latex/syntaxes/Bibtex.tmLanguage.json.
New grammar file: file:///Users/USER/.vscode/extensions/james-yu.latex-workshop-9.0.1/syntax/Bibtex.tmLanguage.json
TMScopeRegistry.ts:47 Overwriting grammar scope name to file mapping for scope text.tex.markdown_latex_combined.
Old grammar file: file:///Applications/Visual%20Studio%20Code.app/Contents/Resources/app/extensions/latex/syntaxes/markdown-latex-combined.tmLanguage.json.
New grammar file: file:///Users/USER/.vscode/extensions/james-yu.latex-workshop-9.0.1/syntax/markdown-latex-combined.tmLanguage.json
TMScopeRegistry.ts:47 Overwriting grammar scope name to file mapping for scope source.cpp.embedded.latex.
Old grammar file: file:///Applications/Visual%20Studio%20Code.app/Contents/Resources/app/extensions/latex/syntaxes/cpp-grammar-bailout.tmLanguage.json.
New grammar file: file:///Users/USER/.vscode/extensions/james-yu.latex-workshop-9.0.1/syntax/cpp-grammar-bailout.tmLanguage.json

Screenshots

Screen Shot 2022-11-17 at 11 34 19 PM Screen Shot 2022-11-17 at 11 34 32 PM

Desktop [Required]

Additional questions

Are you using VSCodium?

No

Are you using the Snap or Flatpack versions of VS Code?

No

Are you using LaTeX Workshop with VS Code Remote?

No

If the answer is Yes, please write which one you are using. Write the versions of the remote extension.

Additional context

Add any other context about the problem here.

James-Yu commented 1 year ago

This seems to be a bug related to vscode. I cannot find the root cause. @jlelong may you please take a look when there's time?

I've traced down to provideCompletionItems function in completion.ts. The comma , can trigger population of both citation and reference suggestions, returned in provideCompletionItems. However, citation suggestions will show a list of candidate, while references cannot although suggestions were successfully provided. I can't see if there are any hidden functions after provideCompletionItems but before showing the candidate list.

jlelong commented 1 year ago

I would not say this is a bug as I think it has never worked. This is more like a good feature request.

There is indeed a hidden filtering mechanism after provideCompletionItems returns handled directly by vscode and we have very little if no control on it. The filtering mechanism uses the range field of the return completion items if it is defined. Here is the code used for citation completion to support completion after a comma

https://github.com/James-Yu/LaTeX-Workshop/blob/dc3283bf17221ec130c86662333e487edf38d396/src/providers/completer/citation.ts#L103-L109

I will implement this today.

jlelong commented 1 year ago

Currently, reference completion explicitly sets range to start right after the opening {

https://github.com/James-Yu/LaTeX-Workshop/blob/982c410bacb73b95a8f67751d83fa523823d4c04/src/providers/completer/reference.ts#L111-L117

See this very good post explaining the filtering mechanism.

alw-personal commented 1 year ago

Wow! Many thanks for the very speedy implementation.