AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   General (https://forums.alliedmods.net/forumdisplay.php?f=7)
-   -   [Editor] AMXXPawn for Visual Studio Code (https://forums.alliedmods.net/showthread.php?t=300661)

klippy 08-25-2017 00:04

[Editor] AMXXPawn for Visual Studio Code
 
AMXXPawn Language Service for VSCode


An extension for Visual Studio Code that adds support for the AMXXPawn language.


Features

Right now this is pretty much an early preview/beta version with features lacking, and some features even not working properly. Even though it's unfinished, I've posted this solely to get feedback. I encourage you to post in this topic and help me improve this extension.

However, here is a basic preview of currently implemented features:

Visual Studio Code

In case you haven't heart of Visual Studio Code (VSCode) yet - it's an open-source multiplatform text/code editor developed and maintained by Microsoft. It's entirely written in TypeScript using Electron framework. It has many great built-in features like Git integration and Debugging support, but also has support for extensions (just like this one), of which there are many.
VSCode has been my go-to editor for many other languages (especially for Node.js development) for a while now, but it never had proper Pawn support. This extension aims at improving Pawn language support in VSCode.

Official site & Downloads


Installation Instructions

Installation is pretty straightforward, thanks to VSCode's great support for extensions.
All you have to do is to open the Extensions View (by using the bar on the left hand side or pressing Ctrl+Shift+X), search for "amxxpawn" and click the "Install" button, then reload VSCode.
Make sure to install the one with my name as there are two registered amxxpawn extensions.
https://image.prntscr.com/image/unHa...8QmNbx3oCA.png



Source Code
Change Log

Contributions are welcome.
Also, if you have any ideas/suggestions/critiques, please post in this topic.

TODO:
Code:

- Properly parse and resolve #include directives.
    - Right now only #include <filename> format is supported
    - #include "filename" and #include filename should look in the current directory and the list of include directories.
    - #include <filename> should only look in the list of include directories.


- Handle #tryinclude

- Properly handle block comments and scopes (brackets) when parsing files, some edge cases may break the parser

- In addition to functions, parse:
    - Global variables/constants (not completely done)
    - Enumerations
    - #define directives

- Add Go to Definition/Peek Definition for symbols

- Parse doc-comments and display them together with completions and signature help

- Handle dependency timestamps - if a dependency has changed, reparse it

- (maybe) Add basic IntelliSense implementation (requires a new parser):
    - Detect tag mismatches
    - Detect unreachable code
    - Wrong syntax

- (maybe) Make function parameters tag-aware and suggest only (or prioritize) symbols that have the same tag
- (maybe) Make array element access enum-aware and sugest only (or prioritize) members of the same enum

- (maybe) Make the parser scope aware and parse symbols in scopes too so completions can suggest local variables and parameters


JusTGo 08-25-2017 07:45

Re: [Editor?] AMXXPawn Language Service for Visual Studio Code
 
nice, i have a suggestion can you add an option like "Compile plugin" called "Compile plugin local" so it search amxxpc.exe where the .sma folder.

klippy 08-25-2017 08:11

Re: [Editor?] AMXXPawn Language Service for Visual Studio Code
 
Quote:

Originally Posted by JusTGo (Post 2544247)
nice, i have a suggestion can you add an option like "Compile plugin" called "Compile plugin local" so it search amxxpc.exe where the .sma folder.

Strange thing to request. Would you like it to be a setting, so that when it's set to true it first looks for amxxpc in the input path, or just make it a command?

JusTGo 08-25-2017 08:16

Re: [Editor?] AMXXPawn Language Service for Visual Studio Code
 
a command, its not strange its usefull just one press this command it looks for amxxpc.exe or compile.exe in the opened file folder.

klippy 08-25-2017 09:07

Re: [Editor?] AMXXPawn Language Service for Visual Studio Code
 
I've pushed an update for your request. You can update your extension by going to the Extensions View and clicking the "Update" button on the extension entry.

JusTGo 08-25-2017 09:21

Re: [Editor?] AMXXPawn Language Service for Visual Studio Code
 
if possible also check for include folder ect..., like when you open a sma in amxmodx/scripting/ you get evry thing in that folder.

klippy 08-25-2017 16:00

Re: [Editor?] AMXXPawn Language Service for Visual Studio Code
 
Version 0.2.0 has been published, you can install/update it from the Extensions View, as usual.

Code:

[Version 0.2.0] - 2017-08-25

Added
    - Document symbol lookup (Ctrl+Shift+O) - Easy way to search and navigate to any symbol in the currently opened document
    - Symbol completion - displays suggestions as you type

Fixed
    - Included dependencies are now properly managed, no more data leaks

Completions:
https://image.prntscr.com/image/aG7O...P5Z1YWWuMw.png


Document symbol lookup:
https://image.prntscr.com/image/uN79...MyCUybXbfQ.png

Hedgehog Fog 08-25-2017 17:23

Re: [Editor?] AMXXPawn Language Service for Visual Studio Code
 
Good job. Can you make project directory variable for compiler paths?

klippy 08-25-2017 17:38

Re: [Editor?] AMXXPawn Language Service for Visual Studio Code
 
Quote:

Originally Posted by Hedgehog95 (Post 2544365)
Good job. Can you make project directory variable for compiler paths?

Thanks. I don't think I understand what you mean by that. Could you elaborate please?

Hedgehog Fog 08-26-2017 03:23

Re: [Editor?] AMXXPawn Language Service for Visual Studio Code
 
KliPPy,
I mean support of relative paths or special variable for project directory.

For example:

PHP Code:

amxxpawn.compiler.includePaths: [
    
"${project_dir}/compiler/include"
    "
${project_dir}/src/include"


or

PHP Code:

amxxpawn.compiler.includePaths: [
    
"compiler/include"
    "src/include"


So, if compiler/include directory exists in current project then load include from this directory.

JusTGo 08-26-2017 05:46

Re: [Editor?] AMXXPawn Language Service for Visual Studio Code
 
can you add somthing like this :

PHP Code:

  // Where should compiler. Can be:
  //   - 'source' (same as input)
  //   - 'path' (specified in amxxpawn.compiler.executablePath setting)
  
"amxxpawn.compiler.executableType""source"

if source is set in this case it will look amxxpc.exe in the input folder.

PHP Code:

  // Where should include files. Can be:
  //   - 'source' ( include directory,  relative to input directory )
  //   - 'path' (specified in amxxpawn.compiler.includePaths setting)
  
"amxxpawn.compiler.includeType ""source"

will look for include folder.

klippy 08-26-2017 08:56

Re: [Editor?] AMXXPawn Language Service for Visual Studio Code
 
Quote:

Originally Posted by Hedgehog95 (Post 2544411)
KliPPy,
I mean support of relative paths or special variable for project directory.

Can you define "project directory" precisely? In VSCode there are no projects, but workspaces, which are folders that have been opened in VSCode.
So in VSCode there are two contexts: workspace (which only exists if a folder is opened) and currently opened file.

There are THESE substitution variables available, but they are only available within tasks.json, so that doesn't help us here as they are not resolved/expanded within settings.
There is some talk HERE to support it in settings.json (which can be overriden per-workspace) but it hasn't been implemented yet, nor do extensions have a service to resolve those substitution variables.

I can write a substitution variables resolver I guess, but keep reading this post, what I am about to write may help you.

Quote:

Originally Posted by JusTGo (Post 2544429)
can you add somthing like this :

PHP Code:

  // Where should compiler. Can be:
  //   - 'source' (same as input)
  //   - 'path' (specified in amxxpawn.compiler.executablePath setting)
  
"amxxpawn.compiler.executableType""source"

if source is set in this case it will look amxxpc.exe in the input folder.

PHP Code:

  // Where should include files. Can be:
  //   - 'source' ( include directory,  relative to input directory )
  //   - 'path' (specified in amxxpawn.compiler.includePaths setting)
  
"amxxpawn.compiler.includeType ""source"

will look for include folder.

I don't think I want to support that, as there is probably no need. If you really have a folder with many files that may use a different compiler, then read THIS. You can create a .vscode/settings.json in your directory and then set your compiler path there.

Also, here is another (and probably better) solution - why not create a BUILD TASK in .vscode/tasks.json for your workspace?
Here's a working example:
Code:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "Compile Plugin",
            "type": "process",
            "command": "${workspaceRoot}\\amxxpc.exe",
            "args": [
                "${file}",
                "-i${workspaceRoot}\\include",
                "-o${workspaceRoot}\\output\\${fileBasenameNoExtension}.amxx"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

Now when you open any file in that workspace you can just do Ctrl+Shift+B and it will compile your plugin and put it in the output/ directory.

JusTGo 08-26-2017 09:48

Re: [Editor?] AMXXPawn Language Service for Visual Studio Code
 
ok thank build task is what i need.

KiLLeR. 08-26-2017 20:32

Re: [Editor?] AMXXPawn Language Service for Visual Studio Code
 
Is there something like this for Visual Studio (full version)?

klippy 08-26-2017 20:54

Re: [Editor?] AMXXPawn Language Service for Visual Studio Code
 
Quote:

Originally Posted by KiLLeR. (Post 2544599)
Is there something like this for Visual Studio (full version)?

Not as far as I know, as there is really no reason.

Hedgehog Fog 08-27-2017 05:16

Re: [Editor?] AMXXPawn Language Service for Visual Studio Code
 
KliPPy
Yes, I'm talking about an opened folder. I know about workspace configs, but anyway I should write absolute path for include directory, so, yep, relative path will be nice.

klippy 08-27-2017 05:56

Re: [Editor?] AMXXPawn Language Service for Visual Studio Code
 
Quote:

Originally Posted by Hedgehog95 (Post 2544625)
KliPPy
Yes, I'm talking about an opened folder. I know about workspace configs, but anyway I should write absolute path for include directory, so, yep, relative path will be nice.

Can't you use a task? Look at my post again.
If you absolutely need it the way you want it, then I guess I can write a substitution variables resolver.

klippy 08-27-2017 08:31

Re: [Editor?] AMXXPawn Language Service for Visual Studio Code
 
Published version 0.2.1.
Code:

## [Version 0.2.1] - 2017-08-27
### Added
- Handle **#tryinclude** statements and underline if can't resolve, but don't produce an error
- Report unmatched closing braces

### Fixed
- Properly parse and resolve **#include** statements
- Properly handle multiple multiline comments on the same line
- Properly handle multiple braces on the same line


Hedgehog Fog 08-27-2017 08:47

Re: [Editor] AMXXPawn for Visual Studio Code
 
KliPPy
I need autocomplete, not a compiler.

klippy 08-27-2017 08:55

Re: [Editor] AMXXPawn for Visual Studio Code
 
Quote:

Originally Posted by Hedgehog95 (Post 2544660)
KliPPy
I need autocomplete, not a compiler.

Ah, gotcha. I'll do something about it.

klippy 08-27-2017 10:30

Re: [Editor] AMXXPawn for Visual Studio Code
 
Alright, there's a new update.

amxxpawn.compiler.executablePath, amxxpawn.compiler.includePaths and amxxpawn.compiler.outputPath now support variable substitution. You can use the same ones that are defined HERE except ${cwd} and ${lineNumber}. Is that what you needed?

Here's a full changelog:
Code:

## [Version 0.3.0] - 2017-08-27
## Added
- Substitution variables are now allowed in settings containing paths
- More diagnostics to the **#include** statement parser

## Fixed
- **#include** statements parser now provides links and diagnostics with a correct character range


Hedgehog Fog 08-27-2017 14:56

Re: [Editor] AMXXPawn for Visual Studio Code
 
1 Attachment(s)
KliPPy
Works for compiler, but doesn't work for include.

PHP Code:

{
    
"amxxpawn.compiler.includePaths": [
        
"${workspaceRoot}/compiler/include",
        
"${workspaceRoot}/src/include"
    
],
    
"amxxpawn.compiler.executablePath""${workspaceRoot}/compiler/amxxpc.exe"



klippy 08-27-2017 15:50

Re: [Editor] AMXXPawn for Visual Studio Code
 
Aye, totally forgot about the parser. I've pushed an update, should be good now. Keep in mind that includePaths will only support ${workspaceRoot} and ${workspaceRootFolderName} (and any future workspace variables), as the language server has no knowledge of what file is currently open/focused.

Code:

## [Version 0.3.1] - 2017-08-27
### Added
- Reparses open documents when configuration changes

### Fixed
- The parser now substitutes variables in `amxxpawn.compiler.includePaths` too


Hedgehog Fog 08-27-2017 17:30

Re: [Editor] AMXXPawn for Visual Studio Code
 
KliPPy
It works, thanks.
I use "Ctrl + Mouse Click" to go to definition, but it opens documentation after click, can you add option to disable this?

klippy 08-27-2017 17:49

Re: [Editor] AMXXPawn for Visual Studio Code
 
You can use F12 to go to or Alt+F12 to peek definition too. But yeah, I don't like that links and definitions are "clashing" either, I've been thinking a about a solution to that.
I guess I can add a setting in the next update, but I won't be pushing an update for that feature only. I hope you can live with it for a day or two.

Anyway, what are your overall thoughts? You've provided a great deal of feedback already and thank you for that. :^)

Hedgehog Fog 08-27-2017 18:00

Re: [Editor] AMXXPawn for Visual Studio Code
 
Quote:

You can use F12 to go to or Alt+F12 to peek definition too.
I know. :)

Quote:

I guess I can add a setting in the next update, but I won't be pushing an update for that feature only. I hope you can live with it for a day or two.
Sure. :wink:

Quote:

Anyway, what are your overall thoughts? You've provided a great deal of feedback already and thank you for that. :^)
Thank you for this great extension. I tried to do it myself, but I didn't have enough time and I abandoned it.

Also I wrote simple plugin for gulp to compile sma and I using it in my project, so now I need only autocompletion. :)
https://www.npmjs.com/package/gulp-sma

P.S

voed 08-28-2017 18:36

Re: [Editor] AMXXPawn for Visual Studio Code
 
Can we disable this messages? Its using so much space. Thank you.
http://i.imgur.com/s9DhHvs.png

klippy 08-29-2017 06:02

Re: [Editor] AMXXPawn for Visual Studio Code
 
Quote:

Originally Posted by voed (Post 2545000)
Can we disable this messages? Its using so much space. Thank you.
...

I'm really failing to see how they take too much space, but sure, I'll add a setting for that.

voed 08-29-2017 09:44

Re: [Editor] AMXXPawn for Visual Studio Code
 
Quote:

Originally Posted by KliPPy (Post 2545052)
I'm really failing to see how they take too much space

Like this:
http://i.imgur.com/fArRHWS.png

Also, is that possible to highlight warnings/errors right in code window? Like in sublime text:
http://i.imgur.com/1WE6pXw.png

klippy 08-29-2017 09:58

Re: [Editor] AMXXPawn for Visual Studio Code
 
Quote:

Originally Posted by voed (Post 2545078)

I am fully aware of what messages you are talking about, but what I said is that I'm failing to see how they take "so much space". What's more, I find them quite useful so you can easily spot mistakes in the compiler configuration (the printed process arguments) and tell when the compiler exited or perhaps if the process hanged.

Quote:

Originally Posted by voed (Post 2545078)
Also, is that possible to highlight warnings/errors right in code window? Like in sublime text:
http://i.imgur.com/1WE6pXw.png

I don't quite remember ST3 having that functionality. Is that a plugin? Link me to whatever it is so I can inspect it and see what you are precisely talking about.

wopox3 08-29-2017 12:40

Re: [Editor] AMXXPawn for Visual Studio Code
 
Quote:

Originally Posted by voed (Post 2545000)
Can we disable this messages? Its using so much space. Thank you.

I support. On a small screen, lines take up a lot of space. Please add an option to disable superfluous compiler output text.

kristi 08-29-2017 14:35

Re: [Editor] AMXXPawn for Visual Studio Code
 
Quote:

Originally Posted by KliPPy (Post 2544203)

Can you make it so it only opens the include file in a new tab?

And maybe Ctrl + Click :arrow: Ctrl + Left Click

klippy 08-29-2017 14:57

Re: [Editor] AMXXPawn for Visual Studio Code
 
Quote:

Originally Posted by kristi (Post 2545172)
Can you make it so it only opens the include file in a new tab?

You can press F12 or Right Click the link then select Go to Definition, but in the new update there will also be an option to disable links to the web API reference.

Quote:

Originally Posted by kristi (Post 2545172)
And maybe Ctrl + Click :arrow: Ctrl + Left Click

There's no way to change that and it's not my doing, it's a part of VSCode's UI. You may go to VSCode GitHub and propose the change.

klippy 08-29-2017 15:40

Re: [Editor] AMXXPawn for Visual Studio Code
 
An update has been published.

Code:

## [Version 0.4.0] - 2017-08-29
### Added
- Suggestions/completions for variables and constants
- Some diagnostics for variable/constant definitions
- `amxxpawn.compiler.showInfoMessages` setting - whether compile process shows additional information (arguments, exit code...)

### Fixed
- `[]` and `()` pairs now highlighted too (only `{}` pairs were before)
- CWD is now set to amxxpc's directory when running it

https://image.prntscr.com/image/VsIm...99ZrG0RJWA.png

https://image.prntscr.com/image/aYho...cfmNYwPryw.png

wopox3 08-30-2017 12:31

Re: [Editor] AMXXPawn for Visual Studio Code
 
https://pp.userapi.com/c638329/v6383...ECrf4rLp0w.jpg
With the syntax highlighting on STATUSICON_HIDE something is not right

klippy 08-30-2017 12:41

Re: [Editor] AMXXPawn for Visual Studio Code
 
STATUSICON_HIDE is fine, STATUSICON_SHOW isn't. It's because highlight is picking up "STATUSICON_SHOW :" as a tag. There's really no reliable way to match Pawn tags with regex only, and language server protocol doesn't allow me to dynamically add decorations to code.
As far as I've seen no other editor provided highlight for tags and I see why - the syntax is so stupid it's not possible (at least not reliably). Do I leave it as it is or just remove highlight for tags completely?

voed 08-30-2017 12:55

Re: [Editor] AMXXPawn for Visual Studio Code
 
I have some suggestions, if its possible, of course:
1. For functions that have arguments, show hint with arguments by clicking on function name:2. Add open parenthesis automatically when autocompleting function name; if function has no arguments, add closing parenthesis too:
  • type "read_fl", click enter, have "read_flags("
  • type "client_put", click enter, have "client_putinserver()"
3. Show define value when hover on its name
http://i.imgur.com/NADQU1z.png
4. May be pointless as hard to implement, but anyway. Show lang file string value on hover by lang key:
http://i.imgur.com/v12Kz80.png

voed 08-30-2017 12:59

Re: [Editor] AMXXPawn for Visual Studio Code
 
Quote:

Originally Posted by KliPPy (Post 2545325)
Do I leave it as it is or just remove highlight for tags completely?

Maybe just keep highlighting for already existing tags : Float:, bool:, Array:, any:, etc

wopox3 08-30-2017 13:18

Re: [Editor] AMXXPawn for Visual Studio Code
 
So in Ternary Boolean you need to remove the syntax highlighting.
Or find a competent way to determine the ternary operation and the declared type inside it.

klippy 08-30-2017 13:24

Re: [Editor] AMXXPawn for Visual Studio Code
 
Quote:

Originally Posted by voed (Post 2545329)
I have some suggestions, if its possible, of course:
1. For functions that have arguments, show hint with arguments by clicking on function name:

That's planned. Will probably do it in near future.

Quote:

Originally Posted by voed (Post 2545329)
2. Add open parenthesis automatically when autocompleting function name; if function has no arguments, add closing parenthesis too:
  • type "read_fl", click enter, have "read_flags("
  • type "client_put", click enter, have "client_putinserver()"

That seems good to me, will do it.

Quote:

Originally Posted by voed (Post 2545329)
3. Show define value when hover on its name
http://i.imgur.com/NADQU1z.png

The parser still doesn't parse #define statements, but it's on TODO. Didn't plan for that hovering thing, but it seems good as well, will try to do it in the future.

Quote:

Originally Posted by voed (Post 2545329)
4. May be pointless as hard to implement, but anyway. Show lang file string value on hover by lang key:
http://i.imgur.com/v12Kz80.png

I'm not sure, may be pointless. If I ever get to implementing that it will be far down the line, seems kind of irrelevant compared to other features that should get implemented first.

Quote:

Originally Posted by voed (Post 2545332)
Maybe just keep highlighting for already existing tags : Float:, bool:, Array:, any:, etc

Yeah I thought about that too. That would probably be the best thing to do.


Thanks for your input. Have some :bacon!: :bacon!: :bacon!:

Quote:

Originally Posted by wopox3 (Post 2545340)
So in Ternary Boolean you need to remove the syntax highlighting.
Or find a competent way to determine the ternary operation and the declared type inside it.

I honestly don't think Regex can do that reliably, as I've said. Maybe though. I'll take a look at amxxpc code and try to figure out how it determines which ':' is for tags and which for ternary operator, may help me.


All times are GMT -4. The time now is 13:01.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.