Как компилировать в visual studio code pawn

Обновлено: 06.07.2024

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!

  • 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 .

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

PowerShell

Command Prompt (cmd.exe)

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

Explanation

"command": "$/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.

Пользователь офлайн

shinra.tensei


Visual Studio Code - визуальный редактор кода, с красивым дизайном.
Сегодня мы будем адаптировать эту программу под язык Pawn.

Начало
Для начала, нужно скачать саму программу. *Кликабельно*
Далее, логично будет ее установить.
После установки, запускаем программу.

После того, как мы насладились этим прекрасным интерфейсом, следует нажать на этот значок:

Изображение

Открывается такое меню, в котором нам нужно ввести pawn и установить первое расширение в списке.

Изображение

Теперь перезапускаем программу, жмем Файл > Открыть папку, и открываем папку с вашим сервером.

Изображение

Теперь мы можем открыть наш мод, если виден синтаксис павна, то мы все сделали правильно :)

Компилирование
Зайдем в папку нашего сервера и создадим папку .vscode


=>

Теперь нужно настроить компилирование, для этого заходим в Задачи > Настроить задачи.

Изображение

Далее тыкаем все как на скринах ниже:

Изображение

Изображение

У нас открылся файл tasks.json
Содержимое этого файла нужно заменить на следующее и сохранить:

Основная часть закончена, теперь нужно забиндить клавишу F5 под компилирование.
Для этого переходим в Файл > Параметры > Сочетание клавиш

Изображение

Теперь нужно кликнуть по keybindings.json

Изображение

Откроется полный список биндов, и пустой список справа. Вставляем следующий код в список справа, не забываем сохранить все это.

Изображение

Кодировка
Переходим в Файл > Параметры > Параметры

Изображение

И добавляем в поле справа следующую строчку, и так же не забываем сохранять все это:

Изображение


Теперь остается выбрать сборку Pawn по умолчанию.

Изображение

Поздравляю, мы все сделали. Теперь мы можем компилировать наш мод нажатием F5.

This tutorial will show you how to set up the PAWN Syntax and PAWN Compiler in Visual Studio. Let's begin.

The following are required to go on with this tutorial:

Before we begin setting up, I advise that you should follow every single step in this tutorial and not skip any steps to ensure proper installation and a working compiler ready to go.

Part One- Installing Visual Studio

Head on over to the link provided above to download Visual Studio Code. Once on the page, select your platform you wish to download Visual Studio Code for.

You can also scroll down on the page for an insight on some of the core features which makes Visual Studio so awesome.

Once your download begins, wait for it to finish. Once finished, open up the installer to begin the installation process.

Now, this process and easy and fairly simple so I won't provide any more details on it. Just read and agree to the terms, select the installation path of your choice, etc.. and let it install.

Installing the PAWN Syntax

I take no credit for the PAWN Syntax, all of it goes to Diego Cea for creating it.

Once you've completed the installation process, launch Visual Studio. When you've opened it, a 'Welcome' document will open up just to showcase the editor itself. You can go on and read the document as it has some useful information, but this is your choice.

Now that we've got that out of the way, click on the 'Extensions' tab or press CTRL+SHIFT+X together. You'll find the tab on the left side of the editor.


The extensions tab, highlighted in red.

Once on the tab, find the search box. Click on the box, and type in 'PAWN', the first extension that should come up will be named 'Pawn Scripting Language Support.' Click on the extension, on the right side it should come up with the page detailing out all the information about the extension. You should then be able to see a green button called Install, click on it and let it install (in this case, I already have it installed so it won't give me the option to install it again). Once it installs, you will receive a message saying its been installed and that the editor must reboot. Click on the reboot button and let the editor reboot, it should only take a couple of seconds to come back.


1. The search box, 2. The PAWN Syntax extension, 3. Install button

Once rebooted, go ahead and open up a .pwn file. You should notice that all functions, macros and such will be colored instead of being white. This means you have successfully installed the syntax highlighting. Note that colors may depend on the type of theme you are using.


The PAWN Syntax in action.

  • Installed Visual Studio
  • Installed the PAWN Syntax Highlighting Extension

Part Two - Setting up the compiler

Lets begin setting up the compiler.

Start off by creating a shortcut for Visual Studio. Simply right click on Visual Studio Code.exe and click on 'Create Shotcut.' Once you've done that, drag the created shortcut into the folder of your project. For example, I have folder solely dedicated to my server. It has everything including the SAMP server package in it. Thats where my .pwn files are, so I'll put the .exe in there.

Once you done that, run the .exe shortcut you just created from inside your projects folder. Right after you open Visual Studio Code from your projects folder, you should notice that a .vscode folder has been created where the .exe launched from.


The .vscode folder will be created right after you launch the .exe from your projects folder.

Once you've seen that a folder has been automatically created, head back into Visual Studio Code.

From inside Visual Studio, click on Tasks > Configure Tasks. You should see a new file named tasks.json has opened up. In the file, copy and paste the following into it:


The tasks.json file.

Now we wont need to change the path of the PAWN compiler since workspaceRoot means where we launched Visual Studio from. Thats where our pawno folder is.

Once you've entered the above in, hit CTRL+S (This will save the file. It should automatically save it into .vscode without asking you to do it). You can now close the file.

Now that we have the compiler set up, we now have to set up the key binding in order to compile. As most people use PAWNO, the compile binding is F5. We haven't set that up yet, but its pretty simple. Lets do it.

Head on over to File > Preferences > Keyboard Shortcuts. It should open up a file with all keybinds automatically assigned. We want to create and add our own, so right under the search box, click on keybindings.json.


All keybindings can be added here.

Once you've done that, it should open up two files in one. Now on the left side is all the default keybinding, we don't want to change that. What we want to do is add our own, so that will be on the right side in keybindings.json.

Copy the below, and paste it into the right panel (keybindings.json).


Custom key bindings can be added into keybindings.json.

Once the code above has been pasted into the .json file, hit CTRL + S once again to save the file. It shouldn't ask you where to save it. You can now close the file.

To set the PAWN Compiler as the default compiler for Visual Studio Code, simply go to Tasks > Configure Default Build Task and select the PAWN option. Once you've done this, you won't have to keep choosing what type of compiler option to use when compiling. Instead, it will just start compiling with the PAWN compiler.

  • Installed Visual Studio
  • Installed the PAWN Syntax Highlighting Extension
  • Successfully set up the PAWN Compiler

Special thanks to Chaser98 for creating the auto completions library. If you'd like to use auto completions to make work flow easier, visit this link https://github.com/adamw01/pawn-vs-code-completions and copy all of the contents from pawn.json. Once you have copied everything, head back into the editor and press CTRL+SHIFT+P while on a .pwn file and select "Open user snippets." You can then paste all the contents from the GitHub repo into pawn.json which the editor created.

Following the steps above should give you a working PAWN syntax highlighting and a PAWN compiler in Visual Studio. Let's go ahead and test it out and see if it works. Before doing this, you can close Visual Studio and open it again just to reboot the software itself.

Open the editor back up from your project folder, then open up any PAWN file, write some stuff in it. Once done, press F5.


A .pwn script successfully compiled in Visual Studio Code.

So there we go, PAWN syntax highlighting and a PAWN compiler in Visual Studio. From here on you may start working on your scripts as it should be fully functional.

    - Visual Studio Main Site - Visual Studio Documentation - Visual Studio Code Documentation - Visual Studio Marketplace - Visual Studio Code Themes


If you require assistance, want to ask a question or anything else, then please post here in this thread and I'll be sure to help you out as soon as possible !

1) How do I show the auto complete functions without the ones that don't have auto complete?

2) When compiling with YSI 4.0, I get errors on Visual Studio Code but none on PAWNO?

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!

  • Static Analysis
  • Auto-complete
  • Intellisense support

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!

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 .

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

Command Prompt (cmd.exe)

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

"command": "$/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).

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.

Читайте также: