-
Notifications
You must be signed in to change notification settings - Fork 5
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
Twig without frameworks #52
Comments
Nope upd: The best idea I came up with is to implement something similar to the Craft CMS approach. You'll have to create a file that returns the project's Twig environment $twig = new \Twig\Environment($loader, [
// ...
]);
return $twig; and then, in Twiggy internals, something like this will be executed to get all of the information from the environment: /** @var \Twig\Environment $twig */
$twig = require './your/twig.php';
... |
Sound good enough for our use case, look forward see this implemented! |
"twiggy.framework": "twig",
"twiggy.vanillaTwigEnvironmentPath": "path/to/your/twig.php", Ping me when you try the new feature out! |
@moetelo thank you for this new feature! I've loaded twig environment successfully! But errors during load are silent (you have to inspect output of twiggy language server to know if something went wrong). It seems I can't use navigation: imports are not navigable not local nor global (via at-namespace). But doesn't seems to navigate back to definition, nor I see any way to add docs for function, so it could be picked up (maybe via reflection we can traverse back to original function and read php doc comment if any?). Also it doesn't report invalid/non-existent filters, which would be much appreciated, since we can inspect twig and know them all, this would prevent misspelled filters. On a same note when you open suggestions in apply block it doesn't suggest filters (which is the only thing you can use with apply). But when you start to type something it searches for functions: |
For me, this works:
<?php
require __DIR__.'/../vendor/autoload.php';
$loader = new \Twig\Loader\FilesystemLoader();
$loader->addPath('./templates-new', '@global');
$twig = new \Twig\Environment($loader, []);
return $twig; {{ include('@global/example.html.twig') }}
{% include '@global/example.html.twig' %} Ctrl+click on both include paths works as expected What's the output of
|
It returns just an array: D=0 0.0496 Array
(
[0] => __main__
[1] => shared
[2] => global
) To note: we use Twig3.
I assume you should use I've never done vscode extensions development, but have some ts knowledge, if you point me how to setup development env, I can try to debug lsp it locally and see where things go south. |
That would be great!
You should find the Also you might want to install connor4312.esbuild-problem-matchers so the debugger correctly attaches to the process. The php scripts are debugged just using XDebug and |
I've tried to setup package on windows with many errors because I had no clue info about how to generate tree sitter bindings (generate doesn't regenerate bindings by the way, and build via pnpm is started before user script generate call). Gyp patch: diff --git a/packages/tree-sitter-twig/binding.gyp b/packages/tree-sitter-twig/binding.gyp
index ab18082..9af785e 100644
--- a/packages/tree-sitter-twig/binding.gyp
+++ b/packages/tree-sitter-twig/binding.gyp
@@ -3,7 +3,7 @@
{
"target_name": "tree_sitter_twig_binding",
"include_dirs": [
- "<!(node -e \"require('nan')\")",
+ "<!(node -p \"require('node-addon-api').include_dir\")",
"src"
],
"sources": [
@@ -13,6 +13,17 @@
],
"cflags_c": [
"-std=c99",
+ ],
+ 'conditions': [
+ ['OS=="win"', {
+ "msvs_settings": {
+ "VCCLCompilerTool": {
+ "ExceptionHandling": 0,
+ "AdditionalOptions": ["/EHsc"]
+ }
+ },
+ "defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ],
+ }]
]
}
] My succesefull attempt was so far:
Also to start builders I had to modify package to use new tree sitter cli and build via docker (emcc doesn't work on windows due to obscure process.spawn CVE with .bat fix?) diff --git a/packages/tree-sitter-twig/package.json b/packages/tree-sitter-twig/package.json
index 32cb5b2..92c1a5e 100644
--- a/packages/tree-sitter-twig/package.json
+++ b/packages/tree-sitter-twig/package.json
@@ -4,13 +4,13 @@
"description": "Twig grammar for tree-sitter",
"main": "bindings/node",
"scripts": {
- "build": "tree-sitter generate && rm -f ./tree-sitter-twig.wasm",
- "build-wasm": "pnpm build && tree-sitter build-wasm",
+ "build": "pnpx tree-sitter-cli generate && rm -f ./tree-sitter-twig.wasm",
+ "build-wasm": "pnpm build && pnpx tree-sitter-cli build -w",
"test": "tree-sitter test"
},
"license": "Mozilla Public License 2.0",
"dependencies": {
- "nan": "^2.17.0"
+ "node-addon-api": "^8.2.2"
},
"devDependencies": {
"tree-sitter-cli": "^0.20.8"
@@ -19,19 +19,5 @@
"README.md",
"LICENSE",
"tree-sitter-twig.wasm"
- ],
- "tree-sitter": [
- {
- "scope": "twig",
- "file-types": [
- "twig",
- "html.twig"
- ],
- "highlights": [
- "queries/highlights.scm"
- ],
- "injections": "queries/injections.scm",
- "injection-regex": "twig"
- }
]
} Also there was some warning:
I'll post more details when I'll debug some info out of lsp now that I've build it |
We're using twig 3 directly without any framework and custom extension to add filters, functions and tags. Is there any way to configure twiggy to point to custom twig initialization?
The text was updated successfully, but these errors were encountered: