Skip to content

Commit

Permalink
Merge pull request #142 from leftstick
Browse files Browse the repository at this point in the history
* gh-142:
  Polish 'Create Visual Studio Code extension'
  Create Visual Studio Code extension

Closes gh-142
  • Loading branch information
philwebb committed Feb 15, 2023
2 parents c7fa27d + d059539 commit 6cbfe7c
Show file tree
Hide file tree
Showing 31 changed files with 4,662 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ spring-javaformat/spring-javaformat-formatter-eclipse-rewriter/bin
build.log
pid
.factorypath

# npm
node_modules/

# vscode
spring-javaformat-vscode/spring-javaformat/out/
spring-javaformat-vscode/spring-javaformat/runtime/
*.vsix
17 changes: 16 additions & 1 deletion CONTRIBUTING.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,35 @@ To add gradle classes, convert this module to a gradle project.



=== Setting up Visual Studio Code Extension Development
The `spring-javaformat-vscode-extension` extension consists of a formatter written in Java and an extension written in TypeScript.
If you want to work on the TypeScript code it can opened directly with Visual Studio Code.

Maven delegates to `npm run package` to actually generate the extension.

Code is formatted with prettier.
If you need to reform the code you can run `npx prettier --write .`

There is a basic test included with the project, but since it needs UI elements it doesn't run as part of the regular build.
If you make changes to the extension, you should run "`Extension Tests`" from vscode.



=== Importing Into Other IDEs
Maven is well supported by most Java IDEs. Refer to your vendor documentation.



== Understanding the Code
There are quite a few moving parts to this project and the build is quite complex.
At the top level there are 5 projects:
At the top level there are 6 projects:

* `spring-javaformat` - The main formatter project
* `spring-javaformat-eclipse` - The Eclipse plugin
* `spring-javaformat-gradle` - The Gradle plugin
* `spring-javaformat-intellij` - The IntelliJ IDEA plugin
* `spring-javaformat-maven` - The Maven plugin
* `spring-javaformat-vscode` - The Visual Studo Code extension

Under `spring-javaformat` the following projects are defined:

Expand Down
10 changes: 10 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ Once the configuration file is created, configure your IDE to use it:



=== Visual Studio Code
The Visual Studio Code extension provides custom formatter support for Microsoft Visual Studio Code.
The extension using the [`DocumentFormattingEditProvider`](https://code.visualstudio.com/api/references/vscode-api#DocumentFormattingEditProvider) API.
Once installed it may be activated by using the "`Format Document`" action available in the editor context menu or from the Command Palette.

To install the extension select "`Install from VSIX`" in the extensions panel and choose the `spring-javaformat-vscode-extension` vsix file.
You can download the latest version from https://repo1.maven.org/maven2/io/spring/javaformat/spring-javaformat-vscode-extension/{release-version}[Maven Central].



=== About the Conventions
Most of the coding conventions and style comes from the Spring Framework and Spring Boot projects.
Spring Framework manually formats code, where as Spring Boot uses automatic formatting.
Expand Down
29 changes: 27 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.12.1</version>
</plugin>
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
Expand Down Expand Up @@ -362,6 +367,25 @@
<ignore />
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
com.github.eirslett
</groupId>
<artifactId>
frontend-maven-plugin
</artifactId>
<versionRange>
[1.12.1,)
</versionRange>
<goals>
<goal>npx</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
Expand Down Expand Up @@ -597,10 +621,11 @@
</dependencies>
<modules>
<module>spring-javaformat</module>
<module>spring-javaformat-maven</module>
<module>spring-javaformat-gradle</module>
<module>spring-javaformat-eclipse</module>
<module>spring-javaformat-gradle</module>
<module>spring-javaformat-intellij-idea</module>
<module>spring-javaformat-maven</module>
<module>spring-javaformat-vscode</module>
</modules>
<profiles>
<profile>
Expand Down
10 changes: 10 additions & 0 deletions spring-javaformat-maven/spring-javaformat-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>out</directory>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
Expand Down
19 changes: 19 additions & 0 deletions spring-javaformat-vscode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# spring-javaformat-vscode

`spring-javaformat` extension for visual studio code.

![](./format.gif)

## Prerequisites

* Install [node.js](https://nodejs.org/en/download/)
* Install [yarn](https://yarnpkg.com/en/docs/install)
* Install [vsce](https://code.visualstudio.com/api/working-with-extensions/publishing-extension#vsce)

## Generate extension

Just `mvn clean package`


> `spring-javaformat-1.0.0.vsix` will be generated there
Binary file added spring-javaformat-vscode/format.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions spring-javaformat-vscode/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-build</artifactId>
<version>0.0.36-SNAPSHOT</version>
</parent>
<artifactId>spring-javaformat-vscode</artifactId>
<packaging>pom</packaging>
<name>Spring JavaFormat Visual Studio Code</name>
<properties>
<main.basedir>${basedir}/..</main.basedir>
</properties>
<modules>
<module>spring-javaformat-vscode-extension</module>
</modules>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
out
runtime
dist
node
node_modules
.vscode-test/
*.vsix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
out
target
node
.vscode
.vscode-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tabWidth": 2,
"semi": false,
"singleQuote": true,
"printWidth": 120
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": ["dbaeumer.vscode-eslint"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": "build"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": ["${workspaceFolder}/out/test/**/*.js"],
"preLaunchTask": "build"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off",
"java.configuration.updateBuildConfiguration": "interactive"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.gitignore
.prettierrc
.project
.classpath
.vscode/**
.vscode-test/**
.settings/**
out/test/**
**/tsconfig.json
**/tslint.json
**/*.map
**/*.ts
target/**
node/**
src/**
README.md
**pom.xml
Loading

0 comments on commit 6cbfe7c

Please sign in to comment.