James-Yu / LaTeX-Workshop

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

tikz macro completion #4215

Closed DailyShana closed 3 months ago

DailyShana commented 4 months ago

Please fill the following fields with a star (*) and provide as much related information as possible.

Pre-checks*

Please change the following [ ] to [x] for confirmation.

  • [x] The issue has not been reported in this repository.
  • [x] The issue remains after disabling all other extensions and restarting Visual Studio Code.
  • [x] The FAQ cannot address the issue.
  • [x] The issue is not related to compiling a document, or the document can be successfully compiled in the OS terminal but not in Visual Studio Code with this extension.

The Issue*

Please briefly describe the issue you come across.

  • macros begin with \ cannot be autocompleted, begin from version latex workshop 8.28.0

Reproduction Steps

Please list out the steps to reproduce your bug. Include relevant environmental variables or any other configuration.

  1. past the following document
    
    \documentclass{standalone}
    \usepackage{tkz-euclide}
    \begin{document}
    \begin{tikzpicture}
    \tkzDefPoints{0/0/B,6/0/C,4/3.8/A}
    \tkzDrawPolygon(A,B,C)
    \tkzDrawPoints(A,B,C)

\tkzDuplicateSegment(B,C)(C,A)\tkzGetPoint{K} \tkzDuplicateSegment(B,C)(B,A)\tkzGetPoint{L} \tkzDrawSegments(A,K A,L K,L) \tkzDrawPoints(K,L)

\tkzDefTriangleCentercircum\tkzGetPoint{O} \tkzDefTriangleCenterin\tkzGetPoint{I} \tkzDrawSegments(O,I) \tkzDrawPoints(O,I)

\tkzLabelPointsbelow left=-2pt \tkzLabelPointsbelow right=-2pt \tkzLabelPointsleft,yshift=2pt \tkzLabelPointsleft \tkzLabelPointsright \tkzLabelPointsbelow \tkzLabelPointsabove \end{tikzpicture} \end{document}


2. type `\`
3. do not hint \tkz... macros
![2024-03-25_174806](https://github.com/James-Yu/LaTeX-Workshop/assets/8469304/a75b3fd2-9f75-4a55-9324-4dd3f3c7ecd8)

### Expected Behavior
> _What were you expecting to see? Include any relevant examples or documentation links._
- when type `\`, hint \tkz... macros
![2024-03-25_174459](https://github.com/James-Yu/LaTeX-Workshop/assets/8469304/27999d63-7ec1-4aee-b092-1f6128372851)
jlelong commented 4 months ago

The macros listed in the first sreenshot as token_case_catcode are provided by expl3. Did you set the language type to LaTeX3-expl? Please post the logs of the extension.

The package tkz-euclide has not .cwl files (see https://github.com/LaTeXing/LaTeX-cwl) and hence the extension has no knowledge of the macros it provides. The extension does not parse tikzpicture environments to discover newly used macros because their content is way too much sophisticated for standard LaTeX parsers.

DailyShana commented 4 months ago

So, we need a .cwl for tkz-euclide?

token_case_catcode do not appear in the above minicase but in my actual working file. It's showing that the language type is latex but not latex-expl: image

Outputs here:

LaTeX Workshop Output*

[21:13:46.226][Extension] Initializing LaTeX Workshop.
[21:13:47.712][Build][Recipe] Set $LATEXWORKSHOP_DOCKER_LATEX: ""
[21:13:48.418][Server] Creating LaTeX Workshop http and websocket server.
[21:13:49.133][Format][Bib] Bibtex format config: {"tab":"  ","case":"lowercase","left":"{","right":"}","trailingComma":false,"sort":["key"],"alignOnEqual":true,"sortFields":false,"fieldsOrder":[],"firstEntries":["string","xdata"]}
[21:13:49.406][Server] Server successfully started: {"address":"127.0.0.1","family":"IPv4","port":54334} .
[21:13:49.412][Extension] Extension root: c:\Users\Surface\.vscode\extensions\james-yu.latex-workshop-9.19.1
[21:13:49.413][Extension] $PATH: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\Git\cmd;C:\texlive\2024\bin\windows;C:\Users\Surface\AppData\Local\Microsoft\WindowsApps;
[21:13:49.413][Extension] $SHELL: undefined
[21:13:49.416][Extension] $LANG: undefined
[21:13:49.416][Extension] $LC_ALL: undefined
[21:13:49.417][Extension] process.platform: win32
[21:13:49.419][Extension] process.arch: x64
[21:13:49.420][Extension] vscode.env.appName: Visual Studio Code
[21:13:49.420][Extension] vscode.env.remoteName: undefined
[21:13:49.421][Extension] vscode.env.uiKind: 1
[21:13:49.431][Config] latex-workshop.latex.recipes: [{"name":"xetex","tools":["xetex"]},{"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"]}] .
[21:13:49.442][Config] latex-workshop.latex.tools: [{"name":"xetex","command":"xetex","args":["--synctex=-1","--interaction=nonstopmode"],"env":{}},{"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":{}}] .
[21:13:49.500][Config] latex-workshop.latex.autoBuild.run: "never" .
[21:13:49.517][Config] latex-workshop.view.pdf.viewer: "customEditor" .
[21:13:49.756][Extension] Trigger characters for intellisense of LaTeX documents: ["\\",",","{"]
[21:13:49.761][Root] Current workspace folders: undefined
[21:13:49.763][Extension] LaTeX Workshop initialized.
[21:13:49.764][Root] Found root file from active editor: c:\Users\Surface\Documents\TeX Files\****.tex
[21:13:49.765][Root] Root file changed: from c:\Users\Surface\Documents\TeX Files\****.tex to c:\Users\Surface\Documents\TeX Files\****.tex, langID latex . Refresh dependencies
[21:13:49.765][Event] ROOT_FILE_CHANGED: "c:\\Users\\Surface\\Documents\\TeX Files\\****.tex"
[21:13:49.766][Cacher][Watcher] Reset.
[21:13:49.766][Cacher][Watcher] Reset.
[21:13:49.770][Cacher] Adding c:\Users\Surface\Documents\TeX Files\****.tex .
[21:13:49.772][Cacher][Watcher] Watched c:\Users\Surface\Documents\TeX Files\****.tex with a new .* watcher on c:\Users\Surface\Documents\TeX Files\每周作业 .
[21:13:49.772][Event] FILE_WATCHED: "c:\\Users\\Surface\\Documents\\TeX Files\\****.tex"
[21:13:49.779][Cacher] Caching c:\Users\Surface\Documents\TeX Files\****.tex .
[21:13:49.780][Cacher] Updated inputs of c:\Users\Surface\Documents\TeX Files\****.tex .
[21:13:49.780][Cacher] Parse LaTeX AST: c:\Users\Surface\Documents\TeX Files\****.tex .
[21:13:49.780][Event] ROOT_FILE_SEARCHED
[21:13:49.822][Server] valdOrigin is http://127.0.0.1:54334
[21:13:50.255][Cacher] Parsed LaTeX AST: c:\Users\Surface\Documents\TeX Files\****.tex .
[21:13:50.257][File] Calling kpsewhich to resolve ctexart.cls .
[21:13:52.088][File] kpsewhich returned with 'c:/texlive/2024/texmf-dist/tex/latex/ctex/ctexart.cls'.
[21:13:52.101][Cacher] Updated elements in 1844.80 ms: c:\Users\Surface\Documents\TeX Files\****.tex .
[21:13:52.102][Event] FILE_PARSED: "c:\\Users\\Surface\\Documents\\TeX Files\\****.tex"
[21:13:52.111][Structure] Structure force updated with 0 root sections for c:\Users\Surface\Documents\TeX Files\****.tex .
[21:13:52.112][Event] STRUCTURE_UPDATED
[21:13:53.997][Event] STRUCTURE_UPDATED

Developer Tools Console

workbench.desktop.main.js:sourcemap:651  INFO Initial editor state Object
workbench.desktop.main.js:sourcemap:651  INFO Started local extension host with pid 12160.
workbench.desktop.main.js:sourcemap:1871 Overwriting grammar scope name to file mapping for scope text.tex.
Old grammar file: file:///c%3A/Program%20Files/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/TeX.tmLanguage.json.
New grammar file: file:///c%3A/Users/Surface/.vscode/extensions/james-yu.latex-workshop-9.19.1/syntax/TeX.tmLanguage.json
register @ workbench.desktop.main.js:sourcemap:1871
workbench.desktop.main.js:sourcemap:1871 Overwriting grammar scope name to file mapping for scope text.tex.latex.
Old grammar file: file:///c%3A/Program%20Files/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/LaTeX.tmLanguage.json.
New grammar file: file:///c%3A/Users/Surface/.vscode/extensions/james-yu.latex-workshop-9.19.1/syntax/LaTeX.tmLanguage.json
register @ workbench.desktop.main.js:sourcemap:1871
workbench.desktop.main.js:sourcemap:1871 Overwriting grammar scope name to file mapping for scope text.bibtex.
Old grammar file: file:///c%3A/Program%20Files/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/Bibtex.tmLanguage.json.
New grammar file: file:///c%3A/Users/Surface/.vscode/extensions/james-yu.latex-workshop-9.19.1/syntax/Bibtex.tmLanguage.json
register @ workbench.desktop.main.js:sourcemap:1871
workbench.desktop.main.js:sourcemap:1871 Overwriting grammar scope name to file mapping for scope text.tex.markdown_latex_combined.
Old grammar file: file:///c%3A/Program%20Files/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/markdown-latex-combined.tmLanguage.json.
New grammar file: file:///c%3A/Users/Surface/.vscode/extensions/james-yu.latex-workshop-9.19.1/syntax/markdown-latex-combined.tmLanguage.json
register @ workbench.desktop.main.js:sourcemap:1871
workbench.desktop.main.js:sourcemap:1871 Overwriting grammar scope name to file mapping for scope source.cpp.embedded.latex.
Old grammar file: file:///c%3A/Program%20Files/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/cpp-grammar-bailout.tmLanguage.json.
New grammar file: file:///c%3A/Users/Surface/.vscode/extensions/james-yu.latex-workshop-9.19.1/syntax/cpp-grammar-bailout.tmLanguage.json
register @ workbench.desktop.main.js:sourcemap:1871
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope text.tex.
Old grammar file: file:///c%3A/Program%20Files/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/TeX.tmLanguage.json.
New grammar file: file:///c%3A/Users/Surface/.vscode/extensions/james-yu.latex-workshop-9.19.1/syntax/TeX.tmLanguage.json
register @ TMScopeRegistry.ts:46
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope text.tex.latex.
Old grammar file: file:///c%3A/Program%20Files/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/LaTeX.tmLanguage.json.
New grammar file: file:///c%3A/Users/Surface/.vscode/extensions/james-yu.latex-workshop-9.19.1/syntax/LaTeX.tmLanguage.json
register @ TMScopeRegistry.ts:46
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope text.bibtex.
Old grammar file: file:///c%3A/Program%20Files/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/Bibtex.tmLanguage.json.
New grammar file: file:///c%3A/Users/Surface/.vscode/extensions/james-yu.latex-workshop-9.19.1/syntax/Bibtex.tmLanguage.json
register @ TMScopeRegistry.ts:46
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope text.tex.markdown_latex_combined.
Old grammar file: file:///c%3A/Program%20Files/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/markdown-latex-combined.tmLanguage.json.
New grammar file: file:///c%3A/Users/Surface/.vscode/extensions/james-yu.latex-workshop-9.19.1/syntax/markdown-latex-combined.tmLanguage.json
register @ TMScopeRegistry.ts:46
TMScopeRegistry.ts:46 Overwriting grammar scope name to file mapping for scope source.cpp.embedded.latex.
Old grammar file: file:///c%3A/Program%20Files/Microsoft%20VS%20Code/resources/app/extensions/latex/syntaxes/cpp-grammar-bailout.tmLanguage.json.
New grammar file: file:///c%3A/Users/Surface/.vscode/extensions/james-yu.latex-workshop-9.19.1/syntax/cpp-grammar-bailout.tmLanguage.json
register @ TMScopeRegistry.ts:46
workbench.desktop.main.js:sourcemap:651  INFO [perf] Render performance baseline is 282ms
DailyShana commented 4 months ago

I find \documentclass{ctexart} will cause \tk hint token_case_catcode

jlelong commented 4 months ago

I find \documentclass{ctexart} will cause \tk hint token_case_catcode

You can set latex-workshop.kpsewhich.enabled to false to disable ctexart introspection.

@James-Yu This setting also governs the path resolution of bib files. Maybe, we should use two separate settings.

DailyShana commented 4 months ago

Can we have an new option to parse tikzpicture environments?

jlelong commented 4 months ago

Can we have an new option to parse tikzpicture environments?

Unfortunately no. Tikz code is far too complex to be properly parsed by a non native LaTeX parser. The best solution would be to create a .cwl file for tkz-euclide. It takes time but it is not that difficult to write.

jlelong commented 3 months ago

I have just noticed that a .cwl file for the package tkz-euclide exists in texstudio https://github.com/texstudio-org/texstudio/blob/master/completion/tkz-euclide.cwl. What about adding the file to https://github.com/James-Yu/LaTeX-Workshop/blob/master/dev/cwl.list?

DailyShana commented 3 months ago

Thank you for fixing. Just a question, why not add all cwl files in https://github.com/texstudio-org/texstudio/tree/master/completion at one stroke?

jlelong commented 3 months ago

Just a question, why not add all cwl files in https://github.com/texstudio-org/texstudio/tree/master/completion at one stroke?

Because all the cwl files would definitely weigh too much on the extension size.