Skip to content

Commit 6cbfe7c

Browse files
committed
Merge pull request #142 from leftstick
* gh-142: Polish 'Create Visual Studio Code extension' Create Visual Studio Code extension Closes gh-142
2 parents c7fa27d + d059539 commit 6cbfe7c

31 files changed

+4662
-3
lines changed

Diff for: .gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,11 @@ spring-javaformat/spring-javaformat-formatter-eclipse-rewriter/bin
2323
build.log
2424
pid
2525
.factorypath
26+
27+
# npm
28+
node_modules/
29+
30+
# vscode
31+
spring-javaformat-vscode/spring-javaformat/out/
32+
spring-javaformat-vscode/spring-javaformat/runtime/
33+
*.vsix

Diff for: CONTRIBUTING.adoc

+16-1
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,35 @@ To add gradle classes, convert this module to a gradle project.
167167

168168

169169

170+
=== Setting up Visual Studio Code Extension Development
171+
The `spring-javaformat-vscode-extension` extension consists of a formatter written in Java and an extension written in TypeScript.
172+
If you want to work on the TypeScript code it can opened directly with Visual Studio Code.
173+
174+
Maven delegates to `npm run package` to actually generate the extension.
175+
176+
Code is formatted with prettier.
177+
If you need to reform the code you can run `npx prettier --write .`
178+
179+
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.
180+
If you make changes to the extension, you should run "`Extension Tests`" from vscode.
181+
182+
183+
170184
=== Importing Into Other IDEs
171185
Maven is well supported by most Java IDEs. Refer to your vendor documentation.
172186

173187

174188

175189
== Understanding the Code
176190
There are quite a few moving parts to this project and the build is quite complex.
177-
At the top level there are 5 projects:
191+
At the top level there are 6 projects:
178192

179193
* `spring-javaformat` - The main formatter project
180194
* `spring-javaformat-eclipse` - The Eclipse plugin
181195
* `spring-javaformat-gradle` - The Gradle plugin
182196
* `spring-javaformat-intellij` - The IntelliJ IDEA plugin
183197
* `spring-javaformat-maven` - The Maven plugin
198+
* `spring-javaformat-vscode` - The Visual Studo Code extension
184199

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

Diff for: README.adoc

+10
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,16 @@ Once the configuration file is created, configure your IDE to use it:
268268

269269

270270

271+
=== Visual Studio Code
272+
The Visual Studio Code extension provides custom formatter support for Microsoft Visual Studio Code.
273+
The extension using the [`DocumentFormattingEditProvider`](https://code.visualstudio.com/api/references/vscode-api#DocumentFormattingEditProvider) API.
274+
Once installed it may be activated by using the "`Format Document`" action available in the editor context menu or from the Command Palette.
275+
276+
To install the extension select "`Install from VSIX`" in the extensions panel and choose the `spring-javaformat-vscode-extension` vsix file.
277+
You can download the latest version from https://repo1.maven.org/maven2/io/spring/javaformat/spring-javaformat-vscode-extension/{release-version}[Maven Central].
278+
279+
280+
271281
=== About the Conventions
272282
Most of the coding conventions and style comes from the Spring Framework and Spring Boot projects.
273283
Spring Framework manually formats code, where as Spring Boot uses automatic formatting.

Diff for: pom.xml

+27-2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
<build>
6060
<pluginManagement>
6161
<plugins>
62+
<plugin>
63+
<groupId>com.github.eirslett</groupId>
64+
<artifactId>frontend-maven-plugin</artifactId>
65+
<version>1.12.1</version>
66+
</plugin>
6267
<plugin>
6368
<groupId>com.github.wvengen</groupId>
6469
<artifactId>proguard-maven-plugin</artifactId>
@@ -362,6 +367,25 @@
362367
<ignore />
363368
</action>
364369
</pluginExecution>
370+
<pluginExecution>
371+
<pluginExecutionFilter>
372+
<groupId>
373+
com.github.eirslett
374+
</groupId>
375+
<artifactId>
376+
frontend-maven-plugin
377+
</artifactId>
378+
<versionRange>
379+
[1.12.1,)
380+
</versionRange>
381+
<goals>
382+
<goal>npx</goal>
383+
</goals>
384+
</pluginExecutionFilter>
385+
<action>
386+
<ignore></ignore>
387+
</action>
388+
</pluginExecution>
365389
</pluginExecutions>
366390
</lifecycleMappingMetadata>
367391
</configuration>
@@ -597,10 +621,11 @@
597621
</dependencies>
598622
<modules>
599623
<module>spring-javaformat</module>
600-
<module>spring-javaformat-maven</module>
601-
<module>spring-javaformat-gradle</module>
602624
<module>spring-javaformat-eclipse</module>
625+
<module>spring-javaformat-gradle</module>
603626
<module>spring-javaformat-intellij-idea</module>
627+
<module>spring-javaformat-maven</module>
628+
<module>spring-javaformat-vscode</module>
604629
</modules>
605630
<profiles>
606631
<profile>

Diff for: spring-javaformat-maven/spring-javaformat-maven-plugin/pom.xml

+10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
</properties>
1616
<build>
1717
<plugins>
18+
<plugin>
19+
<artifactId>maven-clean-plugin</artifactId>
20+
<configuration>
21+
<filesets>
22+
<fileset>
23+
<directory>out</directory>
24+
</fileset>
25+
</filesets>
26+
</configuration>
27+
</plugin>
1828
<plugin>
1929
<groupId>org.apache.maven.plugins</groupId>
2030
<artifactId>maven-invoker-plugin</artifactId>

Diff for: spring-javaformat-vscode/README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# spring-javaformat-vscode
2+
3+
`spring-javaformat` extension for visual studio code.
4+
5+
![](./format.gif)
6+
7+
## Prerequisites
8+
9+
* Install [node.js](https://nodejs.org/en/download/)
10+
* Install [yarn](https://yarnpkg.com/en/docs/install)
11+
* Install [vsce](https://code.visualstudio.com/api/working-with-extensions/publishing-extension#vsce)
12+
13+
## Generate extension
14+
15+
Just `mvn clean package`
16+
17+
18+
> `spring-javaformat-1.0.0.vsix` will be generated there
19+

Diff for: spring-javaformat-vscode/format.gif

1.75 MB
Loading

Diff for: spring-javaformat-vscode/pom.xml

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

0 commit comments

Comments
 (0)