Skip to content

Language Server with Definitions Only #2408

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

Merged
merged 51 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c8583a8
Add a test and a definitions provider
wolmir Aug 23, 2022
698e1de
Remove unused logic
wolmir Sep 8, 2022
1a59eca
Refactor getCompletions
wolmir Sep 8, 2022
58e4ae1
Refactor yamlScalarNodeToDocumentSymbol
wolmir Sep 8, 2022
13c4fd8
Refactor DvcYamlModel
wolmir Sep 8, 2022
0295536
Extract onInitialize handler to dedicated method
wolmir Sep 8, 2022
1cb92c7
Remove dupes from DvcLanguageServer
wolmir Sep 8, 2022
8e802f9
Extract documentSelector constant
wolmir Sep 8, 2022
e23e6dd
Add lspClient to Extension class
wolmir Sep 11, 2022
2fe6e6d
Restore disposable exports in extension.ts
wolmir Sep 12, 2022
add9d7f
Make ServerModule class into a method
wolmir Sep 12, 2022
bbb3d74
Add prettier to languageServer
wolmir Sep 12, 2022
0c6e777
Remove commented out config
wolmir Sep 12, 2022
6240fad
Remove unnecessary jest config entries
wolmir Sep 12, 2022
bfca24c
Add swc/jest to languageServer
wolmir Sep 12, 2022
235f7ae
Rename DvcLanguageServer->LanguageServer
wolmir Sep 12, 2022
984de71
Rename DvcTextDocument->TextDocumentWrapper
wolmir Sep 12, 2022
040c3a6
Rename IDvcTextDocument->ITextDocumentWrapper
wolmir Sep 12, 2022
a71072a
Fix test coverage config in languageServer
wolmir Sep 12, 2022
15ee3a0
Collect only from src folder
wolmir Sep 12, 2022
d9c81ea
Refactor dependencies
wolmir Sep 12, 2022
46a47c6
Create onDefinition method
wolmir Sep 12, 2022
bd2104c
Create more connection handler methods
wolmir Sep 12, 2022
a74012f
Add method access specifiers to TextDocumentWrapper
wolmir Sep 12, 2022
735df1b
Remove unnecessary if
wolmir Sep 12, 2022
40c88f9
Remove await before return
wolmir Sep 12, 2022
81373cb
Remove make script
wolmir Sep 12, 2022
06b3c43
Remove useless accessor
wolmir Sep 12, 2022
472d5b3
Remove constructor shorthands
wolmir Sep 12, 2022
7a60f3b
Add a codeAction request test
wolmir Sep 12, 2022
aa35e98
Use a better fixture for the codeActions test
wolmir Sep 12, 2022
1a9f4dc
Drop DVC prefix from LanguageClient
wolmir Sep 13, 2022
b0df752
Simplify lspClient track call
wolmir Sep 13, 2022
d639e06
Add access prefixes in DvcYamlModel
wolmir Sep 13, 2022
002a0d6
Export documentSelector from languageServer
wolmir Sep 13, 2022
52cd53e
Export more regex for readability
wolmir Sep 13, 2022
69ebadb
Simplify Stage::toJSON
wolmir Sep 13, 2022
6a43873
Simplify Stage::addDependencies
wolmir Sep 13, 2022
1dc872e
Make TextDocumentWrapper implement ITextDocumentWrapper
wolmir Sep 13, 2022
21e27bd
Move more logic from DocumentWrapper to DvcYaml
wolmir Sep 13, 2022
8bfae99
Commit lock file
wolmir Sep 13, 2022
2da3578
Move definitions logic to languageServer
wolmir Sep 14, 2022
59b081a
Simplify findLocationFor
wolmir Sep 14, 2022
d2640ef
More readability improvements
wolmir Sep 14, 2022
e7989c1
New PR with only the definitions provider
wolmir Sep 15, 2022
8228d85
Add test-build script to languageServer
wolmir Sep 15, 2022
a7b5a1c
Fix document selector bug
wolmir Sep 19, 2022
124e55e
Fix code styling issues
wolmir Sep 19, 2022
e980168
Fix definition bugs
wolmir Sep 20, 2022
4a3af64
Add test for definitions outside dvc.yamls
wolmir Sep 21, 2022
55f89a1
Add test for file path symbols
wolmir Sep 21, 2022
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
1 change: 1 addition & 0 deletions .codeclimate.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"**/contract.ts",
"demo/**",
"extension/src/test/**",
"languageServer/src/test/**",
"webview/src/react-table-config.d.ts",
"webview/src/shared/components/icons/**"
],
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"prettier.configPath": ".prettierrc.json",
"editor.tabSize": 2,
"typescript.updateImportsOnFileMove.enabled": "prompt",
"npm.exclude": ["**/{demo,.wdio*}/**"],
"cSpell.words": [
"appdirs",
"camelcase",
Expand Down
17 changes: 16 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,25 @@
"path": "webview/",
"group": "build"
},
{
"type": "npm",
"label": "npm: dev - languageServer",
"script": "dev",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"path": "languageServer/",
"group": "build"
},
{
"label": "npm: dev - all",
"isBackground": true,
"dependsOn": ["npm: dev - extension", "npm: dev - webview"],
"dependsOn": [
"npm: dev - extension",
"npm: dev - webview",
"npm: dev - languageServer"
],
"group": {
"kind": "build",
"isDefault": true
Expand Down
3 changes: 2 additions & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,8 @@
"lodash.merge": "4.6.2",
"lodash.omit": "4.5.0",
"tree-kill": "1.2.2",
"uuid": "9.0.0"
"uuid": "9.0.0",
"vscode-languageclient": "8.0.2"
},
"devDependencies": {
"@swc/core": "1.3.1",
Expand Down
4 changes: 4 additions & 0 deletions extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { collectWorkspaceScale } from './telemetry/collect'
import { createFileSystemWatcher } from './fileSystem/watcher'
import { GitExecutor } from './cli/git/executor'
import { GitReader } from './cli/git/reader'
import { LanguageClientWrapper } from './lspClient/languageClient'

export class Extension extends Disposable implements IExtension {
protected readonly internalCommands: InternalCommands
Expand Down Expand Up @@ -92,6 +93,8 @@ export class Extension extends Disposable implements IExtension {
this.setCommandsAvailability(false)
this.setProjectAvailability()

this.dispose.track(new LanguageClientWrapper())

this.resourceLocator = this.dispose.track(
new ResourceLocator(context.extensionUri)
)
Expand Down Expand Up @@ -442,6 +445,7 @@ export class Extension extends Disposable implements IExtension {
}

let extension: undefined | Extension

export function activate(context: ExtensionContext): void {
extension = new Extension(context)
context.subscriptions.push(extension)
Expand Down
7 changes: 5 additions & 2 deletions extension/src/fileSystem/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export const isInWorkspace = (pathOrGlob: string): boolean => {
return definedAndNonEmpty(isContained)
}

export const findFiles = async (relativeGlob: string): Promise<string[]> => {
const files = await workspace.findFiles(relativeGlob)
export const findFiles = async (
relativeGlob: string,
exclude?: string
): Promise<string[]> => {
const files = await workspace.findFiles(relativeGlob, exclude)
return files.map(uri => uri.fsPath)
}
62 changes: 62 additions & 0 deletions extension/src/lspClient/languageClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { workspace } from 'vscode'
import {
LanguageClient,
LanguageClientOptions,
ServerOptions,
TransportKind
} from 'vscode-languageclient/node'
import { documentSelector, serverModule } from 'dvc-vscode-lsp'
import { Disposable } from '../class/dispose'

export class LanguageClientWrapper extends Disposable {
private client: LanguageClient

constructor() {
super()

const clientOptions: LanguageClientOptions = {
documentSelector,

synchronize: {
fileEvents: workspace.createFileSystemWatcher(
'**/*.{yaml,dvc,dvc.lock,json,toml}'
)
}
}

this.client = this.dispose.track(
new LanguageClient(
'dvc-vscode-lsp',
'DVC Language Server',
this.getServerOptions(),
clientOptions
)
)

// Start the client. This will also launch the server
this.start()
}

start() {
this.client.start()

return this
}

stop() {
this.client.stop()
}

private getServerOptions(): ServerOptions {
const debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] }

return {
debug: {
module: serverModule,
options: debugOptions,
transport: TransportKind.ipc
},
run: { module: serverModule, transport: TransportKind.ipc }
}
}
}
2 changes: 2 additions & 0 deletions extension/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default {
devtool: 'source-map',
entry: r('./src/extension'),
externals: {
'dvc-vscode-lsp': 'dvc-vscode-lsp',
'dvc-vscode-webview': 'dvc-vscode-webview',
fsevents: "require('fsevents')",
vscode: 'commonjs vscode'
Expand Down Expand Up @@ -65,6 +66,7 @@ export default {
plugins: [
new CleanWebpackPlugin(),
includeDependency(r('../webview/')),
includeDependency(r('../languageServer/')),
includeFiles(),
new ForkTsCheckerWebpackPlugin()
],
Expand Down
6 changes: 6 additions & 0 deletions languageServer/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const config = require('../.eslintrc')

module.exports = {
...config,
ignorePatterns: [...config.ignorePatterns, 'src/test/fixtures/**']
}
1 change: 1 addition & 0 deletions languageServer/.lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../.lintstagedrc')
1 change: 1 addition & 0 deletions languageServer/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
4 changes: 4 additions & 0 deletions languageServer/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { DocumentFilter } from 'vscode-languageserver'

export const serverModule: string
export const documentSelector: DocumentFilter[]
25 changes: 25 additions & 0 deletions languageServer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* global module, require, __dirname */
/* eslint-disable @typescript-eslint/no-var-requires */

// This is the entry point when this package is used as library from the extension.
// This package MUST NOT be bundled.
const path = require('path')

module.exports.serverModule = path.join(__dirname, 'dist', 'server.js')
module.exports.documentSelector = [
{
language: 'yaml'
},
{
pattern: '**/*.{dvc,dvc.lock}'
},
{
language: 'json'
},
{
language: 'toml'
},
{
language: 'python'
}
]
11 changes: 11 additions & 0 deletions languageServer/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
collectCoverageFrom: ['src/**/*.{ts,tsx}', '!**/*.test.*', '!src/test/*'],
coverageDirectory: 'coverage/jest',
coveragePathIgnorePatterns: ['<rootDir>/src/test/'],
coverageReporters: ['json'],
testEnvironment: 'node',
testPathIgnorePatterns: ['<rootDir>/dist/'],
transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest']
}
}
41 changes: 41 additions & 0 deletions languageServer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "dvc-vscode-lsp",
"version": "0.0.1",
"license": "Apache-2.0",
"engines": {
"node": "*"
},
"peerDependencies": {
"dvc": ">=0.0.1",
"typescript": "*"
},
"dependencies": {
"jsonc-parser": "3.1.0",
"jsonpath-plus": "7.0.0",
"lodash": "4.17.21",
"vscode-languageserver": "8.0.2",
"vscode-languageserver-textdocument": "1.0.4",
"vscode-uri": "3.0.3",
"yaml": "2.1.1"
},
"scripts": {
"build": "rm -rf dist && tsc -b",
"test-build": "rm -rf dist && tsc -b",
"format": "prettier --write '**/*.{js,json,jsx,md,scss,ts,tsx,yaml,yml}'",
"lint:prettier": "prettier -c '**/*.{js,json,jsx,md,scss,ts,tsx,yaml,yml}'",
"lint:eslint": "eslint --cache '**/*.{js,ts,jsx,tsx}'",
"lint:tsc": "tsc --noEmit",
"lint": "run-p 'lint:*'",
"dev": "tsc -b --watch",
"test": "jest --collect-coverage"
},
"devDependencies": {
"@swc/core": "1.2.247",
"@swc/jest": "0.2.22",
"@types/jest": "28.1.8",
"fs-jetpack": "4.3.1",
"lint-staged": "13.0.3",
"jest": "29.0.1",
"jest-environment-node": "29.0.2"
}
}
7 changes: 7 additions & 0 deletions languageServer/src/ITextDocumentWrapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Position } from 'vscode-languageserver-textdocument'
import { Document } from 'yaml'

export interface ITextDocumentWrapper {
getYamlDocument(): Document
offsetAt(position: Position): number
}
Loading