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

Local LSP server that improves functionality like item completion #122

Merged
merged 41 commits into from
Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
477a689
Initial commit with LSP from MS examples
Dec 9, 2018
dae75d4
Code quality fixes
Dec 9, 2018
96c1661
added remote LSP server to run parallel to local LSP server
Dec 9, 2018
b74ee76
removed lspEnabled check as its done in extension already
Dec 9, 2018
a943733
Removed completion from REST
SamuelBrucksch Dec 10, 2018
2effad0
removed comments
SamuelBrucksch Dec 10, 2018
00e7062
Turned Server into a class and extracted validation
SamuelBrucksch Dec 10, 2018
de0fee7
Removed log output
SamuelBrucksch Dec 10, 2018
52568eb
WIP: Added items completion in LSP server
SamuelBrucksch Dec 10, 2018
517d6aa
Code quality changes
SamuelBrucksch Dec 11, 2018
95daf40
made code more robust
SamuelBrucksch Dec 11, 2018
1f6f64c
Added parsing of StateChange and uItemUdate events
SamuelBrucksch Dec 11, 2018
6877a63
Fixed wrongly called cb(error)
SamuelBrucksch Dec 11, 2018
3485db7
removed log output
SamuelBrucksch Dec 11, 2018
b455210
Cleaned up validation to not return anything
SamuelBrucksch Dec 11, 2018
c2bd0d2
Cleaned up and added bit more docs
SamuelBrucksch Dec 11, 2018
49cb1c0
Fixed capital letter of class in import - worked on win but not in linux
SamuelBrucksch Dec 11, 2018
b935d43
Same as before
SamuelBrucksch Dec 11, 2018
f640de2
Removed unused getter
SamuelBrucksch Dec 11, 2018
efbecf8
Code Quality
SamuelBrucksch Dec 12, 2018
4d98ced
Moved @types dependencies to root package.json and cleaned up tsconfi…
SamuelBrucksch Dec 12, 2018
13968e4
Test commit for sign off
Dec 12, 2018
4b699e9
Added author in docs
SamuelBrucksch Dec 18, 2018
c4906a2
Added pure JS impl of server and wrote tests with jest
SamuelBrucksch Dec 20, 2018
9cd26c8
Added more tests, use of preomise instead of callbacks in completionitem
Dec 20, 2018
f825f87
Moved tests to unit folder
SamuelBrucksch Dec 21, 2018
19530a7
Added more tests
SamuelBrucksch Dec 21, 2018
45e2111
Cleaned up and removed TS impl
SamuelBrucksch Dec 21, 2018
45afce8
Fixed compile problems by increasing vscode version
SamuelBrucksch Dec 21, 2018
0625fb5
Fallback to empty array if no items map is present
SamuelBrucksch Dec 21, 2018
792557a
More tests
SamuelBrucksch Dec 21, 2018
175677a
Improved npm scripts
SamuelBrucksch Dec 21, 2018
4cecf38
use bind() instead of anonymous function
SamuelBrucksch Dec 21, 2018
4ec82a4
improved scripts
SamuelBrucksch Dec 21, 2018
54ac6ff
Renamed config properties and removed useRestCompletions as its not
SamuelBrucksch Dec 26, 2018
4efc592
changed config in remote language client
SamuelBrucksch Dec 26, 2018
60893db
Merge branch 'master' of https://github.com/openhab/openhab-vscode in…
SamuelBrucksch Dec 26, 2018
6d76729
removed TODO comment
SamuelBrucksch Dec 26, 2018
1161dcf
added changelog and fixed description for settings
SamuelBrucksch Dec 26, 2018
fc398f9
fixed typo
SamuelBrucksch Dec 26, 2018
e818b21
Removed commented code
Jan 11, 2019
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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ out
node_modules
*.vsix
*.todo
*.zip
*.zip
**/out
**/node_modules
.vscode
.vscode-test
coverage
15 changes: 14 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": [ "${workspaceRoot}/out/src/**/*.js" ],
"outFiles": [ "${workspaceRoot}/**/out/**/*.js" ],
"preLaunchTask": "npm"
},
{
Expand All @@ -23,6 +23,19 @@
"sourceMaps": true,
"outFiles": [ "${workspaceRoot}/out/test/**/*.js" ],
"preLaunchTask": "npm"
},
{
"type": "node",
"name": "lsp-server-jest-tests",
"request": "launch",
"program": "${workspaceFolder}/serverJS/node_modules/jest/bin/jest",
"args": [
"--runInBand",
"--detectOpenHandles"
],
"cwd": "${workspaceFolder}/serverJS",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# openHAB VS Code Extension Change Log

## 0.5.0 - TBD
- Added local LSP server (#122)
- Fixed sorting order in items explorer (#125)
- removed settings param 'restCompletions'
- renamed settings param 'lspEnabled' to 'remoteLspEnabled'
- renamed settings param 'lspPort' to 'remoteLspPort'

## 0.4.1 - 2018-12-09
- Fixed Basic UI Preview (#117)
- Fixed Show in Paper UI command (#117)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ In the unlikely case that your language server is running on a port other than t

```json
{
"openhab.lspPort": 5007
"openhab.remoteLspPort": 5007
}
```

If you don't want to have your openHAB files validated by Language Server, simply disable it in the extension:
```json
{
"openhab.lspEnabled": false
"openhab.remoteLspEnabled": false
}
```

Expand All @@ -107,7 +107,7 @@ The following configuration will allow you to access REST API remotely:
```
"openhab.host": "https://home.myopenhab.org",
"openhab.port": 80,
"openhab.lspEnabled": false,
"openhab.remoteLspEnabled": false,
"openhab.username": "your_myopenhab_email",
"openhab.password": "your_myopenhab_password",
```
Expand Down
30 changes: 30 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "openhab-vscode-extension",
"displayName": "openHAB Visual Studio Code Extension",
"description": "Robust tool for openHAB textual configurations. Includes code snippets, syntax highlighting, language server integration and more.",
"version": "0.4.1",
"publisher": "openhab",
"icon": "../openhab.png",
"repository": {
"type": "git",
"url": "https://github.com/openhab/openhab-vscode.git"
},
"license": "SEE LICENSE IN LICENSE",
"engines": {
"vscode": "^1.30.0"
},
"scripts": {
"postinstall": "vscode-install",
"test": "echo \"No tests in client yet!\""
},
"dependencies": {
"ascii-table": "0.0.9",
"copy-paste": "^1.3.0",
"lodash": "^4.17.4",
"request": "^2.83.0",
"request-promise-native": "^1.0.5",
"underscore.string": "^3.3.5",
"vscode": "^1.1.26",
"vscode-languageclient": "^5.2.1"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
55 changes: 55 additions & 0 deletions client/src/LanguageClient/LocalLanguageClientProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
Disposable,
workspace
} from 'vscode'

import {
LanguageClient,
LanguageClientOptions,
TransportKind,
ServerOptions
} from 'vscode-languageclient'

import * as path from 'path';

/**
* @author Samuel Brucksch
*/
export class LocalLanguageClientProvider {
constructor() { }

public connect(context): Disposable {
// The debug options for the server
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
const debugOptions = { execArgv: ["--nolazy", "--inspect=6009"] };

const serverModule = context.asAbsolutePath(path.join("serverJS", "src", "LSPServer.js"));

// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
const serverOptions: ServerOptions = {
run: {
module: serverModule,
transport: TransportKind.ipc,
},
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: debugOptions,
},
};

const extensions = ["things", "items", "rules", "script", "sitemap", "persist"];
const clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: "file", language: "openhab", pattern: `**/*.{${extensions.join(",")}}` }],
synchronize: {
configurationSection: "openhab",
fileEvents: workspace.createFileSystemWatcher("**/.clientrc"),
},
};

// Create the language client and start the client.
const lc = new LanguageClient("openhabLanguageServer", "Openhab Language Server", serverOptions, clientOptions);
return lc.start();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import {
LanguageClientOptions
} from 'vscode-languageclient'

export class LanguageClientProvider {
export class RemoteLanguageClientProvider {
constructor() {
}

public connect(): Disposable {
let config = workspace.getConfiguration('openhab')
let connectionInfo = {
host: config.host,
port: config.lspPort
port: config.remoteLspPort
}

let extensions = [
Expand All @@ -44,16 +44,15 @@ export class LanguageClientProvider {
}

let clientOptions: LanguageClientOptions = {
documentSelector: ['openhab'],
documentSelector: [{ scheme: "file", language: "openhab", pattern: `**/*.{${extensions.join(",")}}` }],
synchronize: {
configurationSection: 'openhabLSP',
fileEvents: workspace.createFileSystemWatcher('**/*.{' + extensions.join(',') + '}')
configurationSection: "openhab",
fileEvents: workspace.createFileSystemWatcher("**/.clientrc"),
}
}

if (config.useRestApi) {
let lc = new LanguageClient('openHABlsp', 'openHAB Server', serverOptions, clientOptions)
return lc.start()
}
// Create the language client and start the client.
let lc = new LanguageClient('openHABlsp', 'openHAB Server', serverOptions, clientOptions)
return lc.start()
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 10 additions & 10 deletions src/extension.ts → client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import { ItemsProvider } from './ThingsExplorer/ItemsProvider'
import { ItemsCompletion } from './ItemsExplorer/ItemsCompletion'
import { RuleProvider } from './ItemsExplorer/RuleProvider'
import { SitemapPartialProvider } from './ItemsExplorer/SitemapPartialProvider'
import { LanguageClientProvider } from './LanguageClient/LanguageClientProvider'
import { LocalLanguageClientProvider } from './LanguageClient/LocalLanguageClientProvider'
import { RemoteLanguageClientProvider } from './LanguageClient/RemoteLanguageClientProvider'
import { Item } from './ItemsExplorer/Item'
import { Thing } from './ThingsExplorer/Thing'
import { Channel } from './ThingsExplorer/Channel'
Expand All @@ -33,7 +34,7 @@ import * as path from 'path'

let _extensionPath: string;

async function init(disposables: Disposable[], config): Promise<void> {
async function init(disposables: Disposable[], config, context): Promise<void> {

disposables.push(commands.registerCommand('openhab.basicUI', () => {
let editor = window.activeTextEditor
Expand Down Expand Up @@ -162,16 +163,15 @@ async function init(disposables: Disposable[], config): Promise<void> {

disposables.push(commands.registerCommand('openhab.command.things.copyUID', (query) =>
ncp.copy(query.UID || query.uid)))

if (config.restCompletions) {
disposables.push(languages.registerCompletionItemProvider('openhab', itemsCompletion))
}
}

if (config.lspEnabled) {
const languageClientProvider = new LanguageClientProvider()
disposables.push(languageClientProvider.connect())
if (config.remoteLspEnabled) {
const remoteLanguageClientProvider = new RemoteLanguageClientProvider()
disposables.push(remoteLanguageClientProvider.connect())
}

const localLanguageClientProvider = new LocalLanguageClientProvider()
disposables.push(localLanguageClientProvider.connect(context))
}

export function activate(context: ExtensionContext) {
Expand All @@ -180,7 +180,7 @@ export function activate(context: ExtensionContext) {
let config = workspace.getConfiguration('openhab')
context.subscriptions.push(new Disposable(() => Disposable.from(...disposables).dispose()))

init(disposables, config)
init(disposables, config, context)
.catch(err => console.error(err));
}

Expand Down
14 changes: 14 additions & 0 deletions client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "out",
"rootDir": "src",
"lib": ["es6"],
"types":["node"]
},
"include": ["src"],
"exclude": ["node_modules", ".vscode-test"]
}
10 changes: 10 additions & 0 deletions client/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"rules": {
"no-unused-expression": true,
"no-duplicate-variable": true,
"curly": true,
"class-name": true,
"semicolon": ["never"],
"triple-equals": true
}
}
Loading