• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

georgewfraser/java-language-server: Java language server using the Java compiler ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

georgewfraser/java-language-server

开源软件地址:

https://github.com/georgewfraser/java-language-server

开源编程语言:

Java 96.0%

开源软件介绍:

Language Server for Java using the Java compiler API

A Java language server based on v3.0 of the protocol and implemented using the Java compiler API.

CircleCI

Installation (VS Code)

Install from the VS Code marketplace

Installation (other editors)

Vim (with vim-lsc)

  • Checkout this repository
  • Run ./scripts/link_{linux|mac|windows}.sh
  • Run mvn package -DskipTests
  • Add the vim plugin natebosch/vim-lsc to your vimrc
  • Add vim-lsc configuration:
    let g:lsc_server_commands = {'java': '<path-to-java-language-server>/java-language-server/dist/lang_server_{linux|mac|windows}.sh'}
  • See the vim-lsc README for other configuration options.

Note: This tool is not compatible with vim-lsp as it only supports LSPv2.0.

Sublime 3 (with LSP)

  • Checkout this repository
  • Run ./scripts/link_{linux|mac|windows}.sh
  • Run mvn package -DskipTests
  • Open your Sublime 3
  • Install Package Control (if missing)
  • Install the LSP Package (if missing)
  • In Sublime, go to Preferences > Package Settings > LSP > Settings
  • Add this lines to your LSP Settings:
    {
      "clients":
      {
          "jls":
          {
              "enabled": true,
              "command": ["bash", "<path-to-java-language-server>/java-language-server/dist/lang_server_{linux|mac|windows}.sh"],
              "scopes": ["source.java"],
              "syntaxes": ["Packages/Java/Java.sublime-syntax"],
              "languageId": "java"
          }
      }
    }
    

Issues

Features

Javadoc

Javadoc

Signature help

Signature help

Autocomplete symbols (with auto-import)

Auto import 1

Auto import 2

Autocomplete members

Autocomplete members

Go-to-definition

Goto 1

Goto 2

Find symbols

Find workspace symbols

Find document symbols

Lint

Error highlight

Type information on hover

Type hover

Find references

Find references 1

Find references 2

Debug

Debug test

Usage

The language server will provide autocomplete and other features using:

  • .java files anywhere in your workspace
  • Java platform classes
  • External dependencies specified using pom.xml, Bazel, or settings

Settings

If the language server doesn't detect your external dependencies automatically, you can specify them using .vscode/settings.json

{
    "java.externalDependencies": [
        "junit:junit:jar:4.12:test", // Maven format
        "junit:junit:4.12" // Gradle-style format is also allowed
    ]
}

If all else fails, you can specify the java class path manually:

{
    "java.classPath": [
        "lib/some-dependency.jar"
    ]
}

You can generate a list of external dependencies using your build tool:

  • Maven: mvn dependency:list
  • Gradle: gradle dependencies

The Java language server will look for the dependencies you specify in java.externalDependencies in your Maven and Gradle caches ~/.m2 and ~/.gradle. You should use your build tool to download the library and source jars of all your dependencies so that the Java language server can find them:

  • Maven
    • mvn dependency:resolve for compilation and autocomplete
    • mvn dependency:resolve -Dclassifier=sources for inline Javadoc help
  • Gradle
    • gradle dependencies for compilation and autocomplete
    • Include classifier: sources in your build.gradle for inline Javadoc help, for example:
      dependencies {
          testCompile group: 'junit', name: 'junit', version: '4.+'
          testCompile group: 'junit', name: 'junit', version: '4.+', classifier: 'sources'
      }
      

Design

The Java language server uses the Java compiler API to implement language features like linting, autocomplete, and smart navigation, and the language server protocol to communicate with text editors like VSCode.

Incremental updates

The Java compiler API provides incremental compilation at the level of files: you can create a long-lived instance of the Java compiler, and as the user edits, you only need to recompile files that have changed. The Java language server optimizes this further by focusing compilation on the region of interest by erasing irrelevant code. For example, suppose we want to provide autocomplete after print in the below code:

class Printer {
    void printFoo() {
        System.out.println("foo");
    }
    void printBar() {
        System.out.println("bar");
    }
    void main() {
        print // Autocomplete here
    }
}

None of the code inside printFoo() and printBar() is relevant to autocompleting print. Before servicing the autocomplete request, the Java language server erases the contents of these methods:

class Printer {
    void printFoo() {
        
    }
    void printBar() {
        
    }
    void main() {
        print // Autocomplete here
    }
}

For most requests, the vast majority of code can be erased, dramatically speeding up compilation.

Logs

The java service process will output a log file to stderr, which is visible in VSCode using View / Output, under "Java".

Contributing

Installing

Before installing locally, you need to install prerequisites: npm, maven, protobuf. For example on Mac OS, you can install these using Brew:

brew install npm maven protobuf

You also need to have Java 13 installed. Point the JAVA_HOME environment variable to it. For example, on Mac OS:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home/

Assuming you have these prerequisites, you should be able to install locally using:

npm install -g vsce
npm install
./scripts/build.sh

At the time of this writing, the build only works on Mac, because of the way it uses JLink. However, it would be straightforward to fix this by changing scripts/link_mac.sh to be more like scripts/link_windows.sh.

Editing

Please run ./configure before your first commit to install a pre-commit hook that formats the code.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap