Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
Adding Eslint LSP component (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
i328638 authored and amiramw committed Nov 7, 2017
1 parent e870632 commit c7ea4a2
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/components.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ frameworks:
- "JavaBuildpack::Framework::YourKitProfiler"
- "JavaBuildpack::Framework::JavaOpts"
- "JavaBuildpack::Framework::LanguageServerBinExecJDT"
- "JavaBuildpack::Framework::LanguageServerNodeESLINT"

# - "JavaBuildpack::Framework::LanguageServerNodeCDX"
11 changes: 11 additions & 0 deletions config/language_server_node_eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# TODO License.

# Configuration for the JAVA LSP server component
---
version: 0.0.+
repository_root: "https://lsp-component-eslint.cfapps.eu10.hana.ondemand.com/"
env:
workdir: language_server_node_eslint/server/
exec: language_server_node_eslint/launcher.sh
ipc:
protocol: "stream"
86 changes: 86 additions & 0 deletions lib/java_buildpack/framework/language_server_node_eslint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Encoding: utf-8
# TODO License.

require 'java_buildpack/component/versioned_dependency_component'
require 'java_buildpack/framework'
require 'fileutils'
require 'java_buildpack/util/qualify_path'
require 'java_buildpack/logging/logger_factory'

module JavaBuildpack
module Framework

# Installs ESLINT based LSP server component.
class LanguageServerNodeESLINT < JavaBuildpack::Component::VersionedDependencyComponent

# Creates an instance
#
# @param [Hash] context a collection of utilities used the component
def initialize(context)
super(context)
@logger = JavaBuildpack::Logging::LoggerFactory.instance.get_logger LanguageServerNodeESLINT
end


# (see JavaBuildpack::Component::BaseComponent#compile)
def compile
@logger.debug { "Compile ESLINT" }
# Install node js
FileUtils.mkdir_p @droplet.root + "nodejs"
nodedir = @droplet.sandbox + "nodejs"
comp_version = @version
comp_uri = @uri
@version="8.0.0"
@uri="https://buildpacks.cloudfoundry.org/dependencies/node/node-8.0.0-linux-x64-ade5a8e5.tgz"
download_tar( target_directory=nodedir )
@version = comp_version
@uri = comp_uri
download_zip strip_top_level = false
@droplet.copy_resources

end

# (see JavaBuildpack::Component::BaseComponent#release)
def release

@logger.debug { "Release ESLINT" }
environment_variables = @droplet.environment_variables
myWorkdir = @configuration["env"]["workdir"]
environment_variables.add_environment_variable(ENV_PREFIX + "workdir", myWorkdir)
myExec = @configuration["env"]["exec"]
environment_variables.add_environment_variable(ENV_PREFIX + "exec", myExec)

myIpc = @configuration["env"]["ipc"]
@logger.debug { "ESLINT Env vars IPC:#{myIpc}" }
myIpc.each do |key, value|
environment_variables.add_environment_variable(ENV_PREFIX + key, value)
end

environment_variables.add_environment_variable 'PATH', "/home/vcap/app/.java-buildpack/#{@droplet.component_id}/nodejs/bin:$PATH"
end

protected

# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
def supports?
@application.environment.key?(LSPSERVERS) && @application.environment[LSPSERVERS].split(',').include?("eslint")
end

private

LSPSERVERS = 'lspservers'.freeze

private_constant :LSPSERVERS

BINEXEC = 'exec'.freeze

private_constant :BINEXEC

ENV_PREFIX = 'LSPESLINT_'.freeze

private_constant :ENV_PREFIX

end

end
end
3 changes: 3 additions & 0 deletions resources/language_server_node_eslint/launcher.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

exec ../nodejs/bin/node ./out/server.js --stdio

0 comments on commit c7ea4a2

Please sign in to comment.