Jump to content

Visual Studio Code for ProcessWire Developers


kongondo

Recommended Posts

@AndZyk not sure, but that seems to be the same thing that I posted earlier just not for vscode but for visual studio?

  Quote

Last week, the Visual Studio Code team released the Remote Development extensions (for Visual Studio Code Insiders) to enable connecting your local tools to a WSL, Docker container, or SSH environment, while retaining the full-fidelity, editing experience in Visual Studio Code (e.g. extensions, themes, debugging). Today, we’re excited to share an early look at Visual Studio Remote Development, which will enable Visual Studio users to achieve the same benefits, and go beyond the limits of their local dev machines.

Expand  

 

Link to comment
Share on other sites

Snippet to easily add Inputfields with intellisense support ? 

  "Get PW Inputfield": {
    "prefix": "field",
    "body": [
      "/** @var Inputfield$1 \\$${2:f} */",
      "\\$${2:f} = \\$this->modules->get('Inputfield$1');"
    ],
    "description": "Get PW Inputfiel"
  },

snippet.gif.e4d1e9c20aa23736b00c8788fbdf9e3a.gif

PS: Turns out that the chaining syntax as shown in the demo does not properly work with intellisense, so I'll use single line method calls in the future ?

  • Like 4
Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...
  • 1 month later...

Building lots of process modules? This snippet might be something for you (hit ctrl+shift+p and type "snippets" and create/edit php.json):

  Reveal hidden contents

And one for creating the execute methods. I'm almost always rendering forms in those methods, no standard html, so this makes me more efficient:

  Reveal hidden contents

snippets.gif.12c798e943df02be232884b559ddbd0d.gif

  • Like 7
Link to comment
Share on other sites

Does anybody of you know if/how it is possible to get intellisense support for methods that are added via hook?

$wire->addHook("Page::foo", function() { ... });

So when I type "$page->" in my editor it should list "foo" as suggestion...

Link to comment
Share on other sites

  • 1 month later...

That's not only for PW development but if you've never tried the remote development feature of vscode you should definitely check it out!

I'm using it for all SSH related stuff now (server administration) and it's been an awesome experience so far. Compared to the console you get a lot of benefits:

  • open any file directly in vscode for editing ( "code foo.txt" will open foo.txt in vscode )
  • upload files via drag&drop, download via right click
  • add different folders to your workspace (eg you can attach /var/www/vhosts and /etc/apache2)
  • use ctrl+p to quickly search for files
  • use the GUI to quickly search for any text in any files/folders
  • get a full and awesome GIT integration (+GUI)
  • extremely easy setup, just download the extension, add a host (host + user) and it works (using ssh keys)

8vCOlMW.png

In the left bottom corner you can see that I'm connected to a remote host. Working on it is just as if it was your local machine ? Intelephense does not work, but I develop locally anyhow and for all server administration stuff there is really everything I need.

  • Like 3
Link to comment
Share on other sites

Snippet for adding a module config class:


  "Module Config Class": {
    "prefix": "moduleConfig",
    "body": [
      "class ${YourModule}Config extends ModuleConfig {",
      "  public function getDefaults() {",
      "    return [",
      "      'fullname' => '',",
      "    ];",
      "  }",
      "  public function getInputfields() {",
      "    \\$inputfields = parent::getInputfields();",
      "    ",
      "    \\$f = \\$this->modules->get('InputfieldText');",
      "    \\$f->attr('name', 'fullname');",
      "    \\$f->label = 'Full Name';",
      "    \\$f->required = true;",
      "    \\$inputfields->add(\\$f);",
      "    ",
      "    return \\$inputfields;",
      "  }",
      "}",
      "",
    ],
    "description": "Module Config Class"
  },

Lqg5a07.gif

  • Like 4
Link to comment
Share on other sites

  • 1 month later...

@szabesz had already mentioned it in this thread. But I think it is worth picking up again.

I recently switched to https://vscodium.com/ and it is working absolutely great. It removes Microsofts branding and, more importantly usage telemetry. It is available for all platforms. Only drawback I could see is not having automated one-click updates.

I'm all for open source and privacy. Microsoft's VS Code is based on the same codebase as VSCodium only MS adds their branding and collects lots of data because, well, that is just what they love to do.

Being a Linux user for more than 15 years now, I really appreciate MS releasing this phantastic editor to the community. At least they are giving back a fraction of what they earned over the last decades with their half baked software which they make their beta testers pay a lot of money for. Ingenious concept, though...  

  • Like 5
Link to comment
Share on other sites

  • 2 months later...
  • 1 month later...
  • 1 month later...

VSCode with intelephense, in the Problems tab I always get this error for __() language string function

1937865171_2020-05-06-114443.png.21870f838d89176b204f7f654a304abd.png

Anyone knows how to get rid of this?

Just found out that it was a namespace problem. When namespace ProcessWire is not declared, intelephense will throw this error.

Link to comment
Share on other sites

  On 5/6/2020 at 6:52 AM, kongondo said:

Other than that, it should go away if you add wire as a folder in the workspace.

Expand  

The wire folder is already in my workspace. Or do you mean I have to add it in VSCode in the workspace settings?

After adding namespace ProcessWire to my template files, I got rid of these errors.

  • Like 1
Link to comment
Share on other sites

  On 5/6/2020 at 8:22 AM, gebeer said:

Or do you mean I have to add it in VSCode in the workspace settings?

Expand  

I meant File > Add Folder to Workspace but it seems you had this setup already.

  On 5/6/2020 at 8:22 AM, gebeer said:

After adding namespace ProcessWire to my template files, I got rid of these errors.

Expand  

Ah. I see. In my case I always namespace my template files as well. In your case, it was looking for the function definitions in the global namespace, hence the error. 

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

Do you guys have a recommendation how to sort method names of a class by their name alphabetically? Thx ? 

// turn this
Class Foo {
  public function foo() {}
  public function bar() {}
}

// into that
Class Foo {
  public function bar() {}
  public function foo() {}
}

 

Link to comment
Share on other sites

×
×
  • Create New...