Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Visual Studio Code extension #142

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 3 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ Once the configuration file is created, configure your IDE to use it:
* Specify the appropriate `Checkstyle version`
* Add your Checkstyle configuration file

=== Visual Studio Code
The vscode extension provides custom formatter support for Visual Studio Code.
The extension is automatically activated whenever a `.java` file is opened. And it requires a few seconds to warm-up while you start with the first workspace.


=== About the Conventions
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.
22 changes: 22 additions & 0 deletions spring-javaformat-vscode/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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.16-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-format-service</module>
</modules>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"configurations": [
{
"type": "java",
"name": "CodeLens (Launch) - FormatterWebApplication",
"request": "launch",
"mainClass": "io.spring.format.FormatterWebApplication",
"projectName": "spring-javaformat-format-service"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.formatOnSave": true,
"java.format.enabled": false
}
129 changes: 129 additions & 0 deletions spring-javaformat-vscode/spring-javaformat-format-service/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?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-vscode</artifactId>
<version>0.0.16-SNAPSHOT</version>
</parent>
<artifactId>spring-javaformat-format-service</artifactId>
<packaging>jar</packaging>
<name>Spring JavaFormat format-service</name>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
</properties>

<build>
<plugins>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.8.RELEASE</version>
<configuration>
<outputDirectory>${main.basedir}/spring-javaformat-vscode/spring-javaformat/runtime/</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<workingDirectory>${main.basedir}/spring-javaformat-vscode/spring-javaformat</workingDirectory>
</configuration>
<executions>
<execution>
<id>exec-yarn-install</id>
<phase>compile</phase>
<configuration>
<executable>yarn</executable>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>exec-package</id>
<phase>package</phase>
<configuration>
<executable>vsce</executable>
<arguments>
<argument>package</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<id>checkstyle-validation</id>
<phase>validate</phase>
<configuration>
<excludes>**/*/FormatterWebApplication.java</excludes>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId>
<version>0.0.16-SNAPSHOT</version>
</plugin>

</plugins>
</build>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- Compile -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-formatter</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Provided -->
<dependency>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-formatter-eclipse-runtime</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2017-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.spring.format;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableScheduling
@SpringBootApplication
public class FormatterWebApplication {

public FormatterWebApplication() {

}

public static void main(String[] args) {
SpringApplication.run(FormatterWebApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2017-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.spring.format.controllers;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.spring.format.request.FormatRequest;
import io.spring.format.tools.FormatContent;

/**
* .
*
* @author Howard Zuo
*/
@RestController
public class FormatController {

@RequestMapping(method = RequestMethod.POST, value = "/format/code")
String formatSource(@RequestBody FormatRequest req) {

return FormatContent.formatContent(req.getSource());

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2017-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.spring.format.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.spring.format.services.HealthService;

/**
* .
*
* @author Howard Zuo
*/
@RestController
public class HealthController {

@Autowired
private HealthService service;

@RequestMapping(method = RequestMethod.GET, value = "/health")
String heartbeat() {
this.service.setLastHeartbeat(System.currentTimeMillis());
return "";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2017-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.spring.format.request;

/**
* .
*
* @author Howard Zuo
*/
public class FormatRequest {

private String source = "";

public void setSource(String source) {
this.source = source;
}

public String getSource() {
return this.source;
}

}
Loading