-
Notifications
You must be signed in to change notification settings - Fork 120
Tokenisation of psalm array types #430
Comments
I was avoiding using this syntax, as there is no vscode extension which is making use of these. However, I think it's a good idea to support complex types, at least these supported by more than one tool (psalm, phan, phpstan etc). Feel free to leave syntax which should be supported and I'll try to get around to this. (I could use weird edge cases for testing.) |
Actually the basic stuff is really simple. In repository:
and then in "php_doc" add one more include.
Is it not OK to contribute to the project? |
Oh, and I use |
Feel free to send PR, just add some testing if possible. I have simple script to generate test cases in Atom's devtools: // source: https://gist.github.com/KapitanOczywisty/ae65eb9809d847d00752896968339730
function specBuild(a){const b=a=>a.replace(/\\/g,"\\\\");a=a.replace(/^\s*\n|\n\s*$/g,"");let c=atom.grammars.grammarForScopeName("source.php").tokenizeLines(a),d=`it 'should tokenize ... correctly', ->\n `;for(let e in(a.match(/\n/g)||[]).length&&(a=`\n ${a.replace(/\n/g,"\n ")}\n `),d+=1<c.length?`lines = grammar.tokenizeLines '''${b(a)}'''\n\n`:`{tokens} = grammar.tokenizeLine '${b(a).replace(/'/g,"\\'")}'\n\n`,c)for(let a in c[e]){let f=JSON.stringify(c[e][a].scopes).replace(/","/g,"', '").replace(/"/g,"'"),g=1<c.length?`lines[${e}][${a}]`:`tokens[${a}]`;d+=` expect(${g}).toEqual value: '${b(c[e][a].value).replace(/'/g,"\\'")}', scopes: ${f}\n`}return`\n${d}\n`}function specPretty(a){let b=function(a){return a.replace(/\\/g,"\\\\")},c=atom.grammars.grammarForScopeName("source.php"),d=c.tokenizeLine(a).tokens,e=`Test code: \`${b(a)}\`\n\n`;for(let c in d){let a=JSON.stringify(d[c].scopes);a=a.replace(/","/g,"\" \"").replace(/"/g,"`").replace(/\[|\]/g,""),e+=`${c}: \`${b(d[c].value)}\` scopes: ${a}\n`}return e}
window.specBuild = specBuild;
window.specPretty = specPretty;
console.log('init.js loaded'); Usage: // single line:
specBuild(`function Foo(#[ParameterAttribute] $parameter) {}`)
// multi line
specBuild(`class Foo {
public static $bar = 'baz';
}`) From the output you should remove not relevant tokens and add test case to |
I am using |
If it is not too much to ask, how do I run tests from the command line? Currently I've only installed |
I'm also using vscode, but I have atom installed just to deal with testing of this repository - it's the easiest way. You can try to replicate what CI is doing, however it's not worth a hustle in my opinion. |
Will Atom deal with this out of the box? |
Yes, open |
Thank you! I will follow your advice. It may take a while and some tries (and maybe my first PR will be rubbish), but I'll get there. Can we leave this open so I can ask questions here please? |
I'm not a member of atom team, just an active contributor, so not a problem for me. Good luck! |
Thanks! Last questions:
|
For personal testing you can use this: https://github.com/KapitanOczywisty/vscode-php-dev You need to change these lines: https://github.com/KapitanOczywisty/vscode-php-dev/blob/master/build/update-grammar.js#L62-L63 then run |
Thanks! I will definitely use your |
@BladeMF Do |
Currently phpactor does not support object-like arrays for completion, but I find the checks by phpstan very useful. |
I'd love to move from intelephense, but seems like phpactor is still rather basic as an IDE. I'm also using phpstan, but It's not helping that much when writing the code. |
Actually, I moved from intelephense because phpactor supports refactoring (I did some of them) and has just as good completion. Also, it's open source so you can contribute the completion from doc comments :-) Currently, for my money, that's the best PHP language server out there. I've worked long years with PHP Tools and later Intelephense. No refactoring kills me. |
Also, you should try |
Summary
Psalm offers very widely supported syntax (by static analysis tools) for documenting array structure. Currently the tokeniser struggles with these forms:
There's probably more cases missing. It will also be a good idea to tokenise the property name with a specific token so its name can be changed.
Motivation
Static analysis is a really powerful tool for avoiding errors, saving time and enforcing coding standards. It really sucks when the IDE is not colouring correctly the syntaxes needed for that analysis. It also provides really good visual feedback and a way of customising the colourisation of the tokens.
Describe alternatives you've considered
I am not aware of any way of customising that tokenisation.
Additional context
I am using VS Code.
Other
I am totally up for PRing this if it is OK to be contributor. I would probably need guidance with testing and setup though - I haven't contributed to a language grammar before.
The text was updated successfully, but these errors were encountered: