Coder Social home page Coder Social logo

vscode-pawn's Introduction

vscode-pawn

Pawn tools for vscode.

Currently this is a port of the Sublime Text package which includes proper Pawn syntax highlighting, autocompletions for the standard library and some popular libraries.

If you like development tools that speed up your workflow and increase productivity, check out sampctl!

Coming soon:

  • Static Analysis
  • Auto-complete
  • Intellisense support

Installation

Just search for "Pawn Tools" in the vscode extensions and install it.

Alternatively, you can check out the source code or view the marketplace page:

Compiling Pawn Code

To actually compile after you've set up the tasks.json below, press CTRL+Shift+B (Windows) or CMD+Shift+B (Mac), or alternatively open up the command palette with CTRL+Shift+P (Windows) or CMD+Shift+P (Mac) and type Run Task, hit enter and select build-normal.

If you use sampctl it's the same process except you'll have four options in the Run Task list:

  • build only - build the package
  • build watcher - build the package on every file change
  • run tests - run the package
  • run tests watcher - run the package on every file change

With sampctl package init

If you're using sampctl, the sampctl package init command will automatically generate a vscode tasks.json if you selected vscode in the editor part of the setup menu.

If you've already got a package but you didn't do this, you can simply download the tasks.json from the Pawn Package template repo.

Once you've done that, there's no more setup needed!

Creating tasks.json

Code uses a method called "Tasks" to run compilers and build tools. All you need to do is create a folder named .vscode in your project's directory and in there, create a file named tasks.json.

https://i.imgur.com/ywElfTy.gif

Then paste the following relevant snippet into that file, depending on your primary shell:

PowerShell

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build-normal",
      "type": "shell",
      "command": "${workspaceRoot}/pawno/pawncc.exe",
      "args": ["${file}", "--%", "-Dgamemodes", "-;+", "-(+", "-d3"],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "isBackground": false,
      "presentation": {
        "reveal": "silent",
        "panel": "dedicated"
      },
      "problemMatcher": "$pawncc"
    }
  ]
}

Command Prompt (cmd.exe)

This example includes no escape characters, so you can adapt this to other shells such as Bash, Oil, Fish, etc.

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build-normal",
      "type": "shell",
      "command": "${workspaceRoot}/pawno/pawncc.exe",
      "args": ["${file}", "-Dgamemodes", "-;+", "-(+", "-d3"],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "isBackground": false,
      "presentation": {
        "reveal": "silent",
        "panel": "dedicated"
      },
      "problemMatcher": "$pawncc"
    }
  ]
}

Explanation

"command": "${workspaceRoot}/pawno/pawncc.exe", is the important bit here, this is the path to your Pawn compiler and I've assumed most of you have a left-over pawno folder from that long dead text editor! This folder not only contains Pawno but also the Pawn code compiler (pawncc.exe). You can safely delete pawno.exe forever.

"args": [...], is also important, this is where you define the arguments passed to the compiler. Pawno also did this but you might not have known. The defaults have always been -;+ to force semicolon usage and -(+ to force brackets in statements.

If you store your Pawn compiler elsewhere, just replace the entire command setting with the full path to your compiler.

Also, if you want to disable debug symbols (you won't be able to use crashdetect) just remove -d3 from "args".

problemMatcher is the part that allows recognising the Pawn compiler output and presenting it in the problems panel of the editor. This doesn't work well with external includes because the paths change from relative to absolute. sampctl fortunately fixes this (and a lot of other annoying things).

Features

Currently just syntax highlighting and completions from the Sublime project.

Once the Pawn-Parser project reaches a workable state, this extension will feature more language features such as intellisense support, go-to-definition, view-all-references, etc...

Here's what the problems panel looks like when the tasks.json is set up properly:

https://i.imgur.com/k8ST5pih.png

vscode-pawn's People

Contributors

adrfranklin avatar bronzal avatar carlos-menezes avatar duydang2311 avatar eoussama avatar healexxzt avatar ohmypxl avatar patrickgtr avatar southclaws avatar sreyas-sreelal avatar vince0789 avatar vsergeenko777 avatar zorono avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

vscode-pawn's Issues

Compiler in OSX

Hello friends!
How do I compile from MAC OSX? I recently purchased the MacBook Air 2019 and I am having immense difficulty compiling.

Already taking advantage of the topic, is there how to run SA-MP on OSX?

SetPlayerAmmo syntax.

SetPlayerAmmo(playerid, weaponslot, ammo) should be SetPlayerAmmo(playerid, weaponid, ammo)

Can't run task.json on linux

I trying so hard changing anything, and it still not working.
Please tell me how to compile using tasks.json on linux (with pawncc)

Suggestion

I don't know if I can suggest here (@Issues) but uhmm,

Is it possible for pawn-tools to have a support on modular gamemodes where as when you #include "..." it will suggest the path like in CSS intellisense,

e.g.
#include "folder/SUGGESTIONS_FOR_FOLDER_CONTENTS_HERE.pwn"

Macros Highlighting problems...

  • missing highlighting for the macro sizeof
  • when i do return function1(playerid); it hightlights return macro only.... and leaves function1 as it is(grey...)

Syntax colouring issue

Hey,

I have been using this for quite sometime now, though I have a problem with this specific syntax I use for my script:

MODULE::Test

Unlike the colouring above, it colours MODULE: as if it was a tag and :Test is white, which is quite annoying, is there any way to fix that?

Add a "debug" mode with help of sampctl and/or crashdetect to listen for run time errors and/or server crashes

I don't know if the vscode API would allow for this (since debugs should have full support for breaking) but it would be cool to have some kind of debug mode when running the package in normal mode or running tests.

This debug mode would be listening the output for runtime errors that crashdetect would output, maybe with the help of sampctl if needed. In the occurrence of a server crash or a run time error, vscode would probably trigger some "fake" break (or something similar or cleaner, I don't know about what the vscode API allows) to directly pinpoint the affected file and line if available, in a similar to how exceptions are pinpointed when debugging C++ in vscode. Obviously, since there's (unfortunately) no plugin/tool to stop and actually debug that yet, there would be no stop at all.

It would be very useful specially when running tests.

Relative include paths aren't working

I recently switched from Sublime Text 3 and all my PAWN projects are written in it. Your package for ST3 allowed relative paths in include directives:

#include "..\include\modules\core\test.pwn"

In VSCode, using this extension, it fails to find the file. Unless, I replace the '..' with its absolute equivalent:

#include "E:\Projects\SAMP\server-master\include\modules\core\test.pwn"

Including .inc files using the bracket notation works fine:

#include <a_samp> // is included as expected

My tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build-normal",
            "type": "shell",
            "command": "E:\\Projects\\SAMP\\compiler\\pawncc.exe",
            "args": ["\\\"${relativeFile}\\\"", "\\\"-;+\\\"", "\\\"-(+\\\"", "\\\"-d3\\\"", "\\\"-Z\\\""],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "isBackground": false,
            "presentation": {
                "reveal": "silent",
                "panel": "dedicated"
            },
            "problemMatcher": "$pawncc"
        }
    ]
}

The folder containing pawncc.exe is separated from my server files.

EDIT N°1:
In the 'problems' tab, I noticed the path to the file in which the error is located is wrong. It has the following form:

E:\Projects\SAMP\gamemodes\servers\server-name\gamemodes\file.pwn

I guess this has something to do with the compiler being elsewhere, right?

EDIT N°2:
I was wondering why it put '/gamemodes/' before the relative path to the current file, and so I figured it must've been built-in the extension, and I believe I found the culprit:
https://github.com/Southclaws/vscode-pawn/blob/master/package.json#L65

EDIT N°3:
I changed the problemMatcher to $sampctl and that seemed to have gotten rid of the problem, however, it can still not find my modules. The paths seem correct now, though.

Also, I just read the README part where it says:

problemMatcher is the part that allows recognising the Pawn compiler output and presenting it in the problems panel of the editor. This doesn't work well with external includes because the paths change from relative to absolute. sampctl fortunately fixes this (and a lot of other annoying things).

I don't know what that means. I've looked into sampctl very briefly, but using it seems like a bit of a stretch. If it turns out that using sampctl is the only viable solution for now, then I will use it.

EDIT N°4:
http://forum.sa-mp.com/showpost.php?p=3976383&postcount=17
This reply makes a lot more sense now that I have been going through the package files. I forked the repository and added another problemMatcher with only ${workspaceRoot} and that didn't seem to fix it; as you have already established. Damn.

Missing expression after unary operator '+'

Missing expression after unary operator '+'.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingExpressionAfterOperator

Compiler/problems output

Alright first things first, I'm sure I could see the compiler output in the "OUTPUT" tab. Since some time i've noticed it doesn't do that anymore - it does show it in the "PROBLEMS" tab and i'm fine with it but I think i've had both before ... not only just one.

EDIT: ok, it's showing in my terminal tab instead

Second; when there's a line on the "PROBLEMS" tab, clicking on one of those lines gives an error saying my file doesn't exists. I assume this has to do something with "relative" stuff. When i click on "create file", that shows next to the error, it creates a directory gamemodes and mygamemode.pwn within my - already existing - gamemodes folder

image

My tasks.json:
tasks.zip

tasks.json

tasks.json code (template) on vscode marketplace differs from the one in github readme and gives error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.