Coder Social home page Coder Social logo

naco-siren / vscode-gradle-language Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 5.0 1.68 MB

A VSCode extension to provide Gradle language support

License: MIT License

TypeScript 100.00%
gradle intellisense plugin visual-studio-code syntax-highlighter keywords-proposed language-server

vscode-gradle-language's Introduction

vscode-gradle-language

Introduction

An extension to provide Gradle language support for Visual Studio Code, including advanced functionalities like Syntax Highlighting, Keyword Auto-completion Proposals and Duplication Validation.

Homepage: Visual Studio Code Marketplace

Structure

The extension observes all .gradle documents and uses the server to provide validation and auto-completion proposals (IntelliSense).

The code for the extension is in the client folder, which uses the vscode-languageclient node module to launch the language server.

The language server is located in the server folder.

The tests are located in the test folder.

Features

Syntax Highlighting

  • The extension converts the sublime-gradle's TextMate grammar configuration for Gradle language.

feature A-1

Keyword Auto-completion Proposals (IntelliSense)

The extension automatically detects the Java and Android plugin used in the Gradle scripts, then propose keywords smartly in different situations depending on the position of the cursor:

  • Inside a line with existing code:

    • At the start of a word:

      • Particularly, after the apply method, propose the parameters for plugin application.

      feature B-1-1-1

      • In a Task Container's constructor:

        • At the start of a parameter, propose Task Container's constructor parameters.

        feature B-1-1-2-1

        • Particularly, after the type parameter, propose Task's default types.

        feature B-1-1-2-2

        • Particularly, after the dependsOn parameter, propose other Tasks names.

        feature B-1-1-2-3

        • Particularly, after the TaskDependency methods (i.e. dependsOn, finalizedBy, mustRunAfter and shouldRunAfter), propose other Tasks names.

        feature B-1-1-2-4

      • Elsewhere, propose the Delegate Object together with its properties and methods.

      feature B-1-1-3

    • After an entity's dot inside a line with existing code, propose the properties and methods of this entity.

    feature B-1-2

  • At the start of a new line:

    • On the root level of the build script, propose the properties and methods of the current script's Delegate Object.

    feature B-2-1

    • Particularly, in a TaskContainer, analyze the task's type and propose the properties and methods according to this type.

    feature B-2-2

    • In a script block of NamedDomainObjectContainer, such as BuildTypes, ProductFlavors, SigningConfigs and AndroidSourceSets, DO NOT override default keywords and let the user decide the name for each item.

    feature B-2-3

    • In a configure closure of an item within a NamedDomainObjectContainer, propose the properties and methods of this container's element type.

    feature B-2-4

    • In a script block of a general property or method, propose the properties and methods of this script block.

    feature B-2-5

Duplication Validation

  • The extension automatically validates the script under editing and warns the user about duplicated script blocks.

feature C-1

Tutorial

Requirements

How to launch the extension

  • Pull the repo and cd to the root directory.
  • Run npm install to initialize the extension and the server.
  • Run npm run compile in the terminal to compile the extension and the server.
  • Open the root folder in Visual Studio Code, then set the Preferences -> Color Theme to Dark+ (default dark).
  • In the Debug viewlet, run Launch Client from drop-down menu (or press F5) to launch the extension and attach to the extension.
  • Create and open a file build.gradle and type 'app' into it. You should see keywords proposed including 'apply'.

How to debug the server

  • In the Debug viewlet, run Attach to Server launch config and set breakpoints in the client or the server.

How to run the tests

  • In the Debug viewlet, run Launch Unit Tests from drop-down menu to run the unit tests.

Known Issues

  • Syntax highlighting doesn't always work consistently with task constructor with parameters in parentheses, i.e. task foo(type: Bar) {...} and task foo {...}

vscode-gradle-language's People

Contributors

ghisvail avatar naco-siren avatar nasirjd avatar tylertian123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vscode-gradle-language's Issues

`Gradle Language Server` log Chinese garbled

Extension Name: Gradle Language Support
Extension Version: 0.2.3
OS Version:window10 21H1
VSCode version:1.62

Describe the bug

After the gradle project is initialized, check the Gradle Language Server log, there are garbled Chinese characters

Screenshots

image

To Reproduce

git pull https://gitee.com/mozhuanzuojing/java-bug01
Open it by VS Code
wait building
view Gradle Tasks log

Expected behavior

Chinese output correctly

Support for Kotlin

Syntax Highlighting should also be enabled for Kotlin (extension *.gradle.kts)

Duplication Validation: "else" has already been used in this build script.

The Duplication Validation feature does not recognize else blocks and treats them like normal script blocks. Therefore, if a build script were to have two or more if...else statements, the plugin will incorrectly warn about "'else' has already been used in this build script".

To Reproduce:

  1. Create a new file and save as Gradle
  2. Enter the following:
if(true){

}
else {

}
if(true) {

}
else {

}

image

false duplication warning

I have a valid build.gradle, and the plugin complains

"repositories" has already been used in this build script.

buildscript {
    repositories {
    }
}
repositories {
}

Publish extension to Open VSX Registry

Hi @naco-siren

Is your feature request related to a problem? Please describe.
Other IDEs based on Eclipse Theia (The engine behind VS Code) like VSCodium, Eclipse Che, GitPod, etc, use Open VSX Registry instead of the proprietary VS Code Marketplace, so this plugin is not available for those using them.

Describe the solution you'd like
I would like that the plugin is deployed to the Open VSX Registry upon release, like it is currently done for the VS Code Marketplace.

The procedure is documented here.

extend the gradle support

I'm a gradle user and I have some ideas to improve the extension.I think it would be great if we add some convenient buttons to run a single task. Besides, we can add an project level explorer in a gradle project like what have done in intellij idea.

Add document formatter for build.gradle

It would be great if we could auto-format the build.gradle file.

When executing formatDocument on the build.gradle file, an alert pops up indicating:
There is no document formatter for 'gradle'-files installed.

Keyboard mapping:

{
  "key": "shift+alt+f",
  "command": "editor.action.formatDocument",
  "when": "editorTextFocus && !editorReadonly"
}

can not build project

Issue Type: Bug

I just initialized a project using spring-boot-vscode-plugin

Could not run phased build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-6.6.1-bin.zip'.
The newly created daemon process has a different context than expected.
It won't be possible to reconnect to this daemon. Context mismatch:
Java home is different.
Wanted: DefaultDaemonContext[uid=null,javaHome=C:\Program Files\Java\jdk1.8.0_231,daemonRegistryDir=C:\Users\fangyuan.xia.gradle\daemon,pid=2232,idleTimeout=null,priority=NORMAL,daemonOpts=-XX:MaxMetaspaceSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xms256m,-Xmx512m,-Dfile.encoding=utf8,-Duser.country=CN,-Duser.language=zh,-Duser.variant]
Actual: DefaultDaemonContext[uid=10343712-1e5d-40d1-aec3-9a04fdca8a56,javaHome=C:\Program Files\Java\jdk1.8.0_231\jre,daemonRegistryDir=C:\Users\fangyuan.xia.gradle\daemon,pid=2704,idleTimeout=10800000,priority=NORMAL,daemonOpts=-XX:MaxMetaspaceSize=256m,-XX:+HeapDumpOnOutOfMemoryError,-Xms256m,-Xmx512m,-Dfile.encoding=utf8,-Duser.country=CN,-Duser.language=zh,-Duser.variant]

Extension version: 0.2.3
VS Code version: Code 1.49.2 (e5e9e69aed6e1984f7499b7af85b3d05f9a6883a, 2020-09-24T16:29:41.983Z)
OS version: Windows_NT x64 10.0.18363

System Info
Item Value
CPUs Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz (8 x 2400)
GPU Status 2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
opengl: enabled_on
protected_video_decode: enabled
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 15.81GB (6.79GB free)
Process Argv --folder-uri file:///d%3A/work/demo/spring-boot-application-listener-demo --crash-reporter-id 519eb0ce-621f-4c61-9be6-06bdba271566
Screen Reader no
VM 0%

Inconsistent Highlighting in `subprojects` closure

This could be consolidated with #2 if it has the same cause, but I'm going to file it separately and let you make the call.

Consider this build.gradle:

// root region
apply plugin: 'base'
task doSomething {
	doLast {
		println "something"
	}
}
subprojects {
	// subprojects region
	apply plugin: 'java'
	task doSomethingElse {
		doLast {
			println "something else"
		}
	}
}

In the "root region," apply and task are highlighted. In the "subprojects region," they are not. It seems like it should behave the same way. Same similar closures, e.g. allprojects.

Spring Initilizr extension - gradle support

I noticed that the Spring Boot Initializr extension does not support editing the build.gradle file after it's downloaded.

I'd like to add support for modifying this file, but it seems like the 'right' way to do this is to use a language server for .gradle files that would let me parse the various methods (e.g. dependencies) in build.gradle, and manipulate them.

I was curious if you had any thoughts on this approach and if I could use this language server as a dependency for that purpose? I don't have much experience with language servers. Any advice yo can give would be appreciated.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.