@herb-tools/language-server 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -7
- package/bin/herb-language-server +0 -16
- package/dist/cli.js +27 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.js.map +1 -1
- package/dist/diagnostics.js +17 -50
- package/dist/diagnostics.js.map +1 -1
- package/dist/formatting_service.js +124 -0
- package/dist/formatting_service.js.map +1 -0
- package/dist/herb-language-server.js +16118 -6762
- package/dist/herb-language-server.js.map +1 -1
- package/dist/index.cjs +29900 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/linter_service.js +44 -0
- package/dist/linter_service.js.map +1 -0
- package/dist/parser_service.js +47 -0
- package/dist/parser_service.js.map +1 -0
- package/dist/project.js +2 -1
- package/dist/project.js.map +1 -1
- package/dist/server.js +72 -61
- package/dist/server.js.map +1 -1
- package/dist/service.js +16 -4
- package/dist/service.js.map +1 -1
- package/dist/settings.js +11 -1
- package/dist/settings.js.map +1 -1
- package/dist/types/cli.d.ts +4 -0
- package/dist/types/config.d.ts +9 -1
- package/dist/types/diagnostics.d.ts +9 -7
- package/dist/types/formatting_service.d.ts +19 -0
- package/dist/types/herb-language-server.d.ts +2 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/linter_service.d.ts +14 -0
- package/dist/types/parser_service.d.ts +10 -0
- package/dist/types/project.d.ts +2 -0
- package/dist/types/server.d.ts +7 -1
- package/dist/types/service.d.ts +6 -0
- package/dist/types/settings.d.ts +11 -0
- package/package.json +22 -24
- package/src/cli.ts +23 -0
- package/src/config.ts +9 -1
- package/src/diagnostics.ts +22 -79
- package/src/formatting_service.ts +150 -0
- package/src/herb-language-server.ts +6 -0
- package/src/index.ts +10 -0
- package/src/linter_service.ts +63 -0
- package/src/parser_service.ts +59 -0
- package/src/project.ts +4 -2
- package/src/server.ts +83 -65
- package/src/service.ts +21 -6
- package/src/settings.ts +24 -2
package/src/server.ts
CHANGED
|
@@ -6,88 +6,106 @@ import {
|
|
|
6
6
|
DidChangeWatchedFilesNotification,
|
|
7
7
|
TextDocumentSyncKind,
|
|
8
8
|
InitializeResult,
|
|
9
|
+
Connection,
|
|
10
|
+
DocumentFormattingParams,
|
|
9
11
|
} from "vscode-languageserver/node"
|
|
10
12
|
|
|
11
13
|
import { Service } from "./service"
|
|
12
14
|
import { HerbSettings } from "./settings"
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
export class Server {
|
|
17
|
+
private service!: Service
|
|
18
|
+
private connection: Connection
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const result: InitializeResult = {
|
|
22
|
-
capabilities: {
|
|
23
|
-
textDocumentSync: TextDocumentSyncKind.Incremental,
|
|
24
|
-
},
|
|
20
|
+
constructor() {
|
|
21
|
+
this.connection = createConnection(ProposedFeatures.all)
|
|
22
|
+
this.setupEventHandlers()
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
supported: true,
|
|
31
|
-
},
|
|
32
|
-
}
|
|
33
|
-
}
|
|
25
|
+
private setupEventHandlers() {
|
|
26
|
+
this.connection.onInitialize(async (params: InitializeParams) => {
|
|
27
|
+
this.service = new Service(this.connection, params)
|
|
34
28
|
|
|
35
|
-
|
|
36
|
-
})
|
|
29
|
+
await this.service.init()
|
|
37
30
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
const result: InitializeResult = {
|
|
32
|
+
capabilities: {
|
|
33
|
+
textDocumentSync: TextDocumentSyncKind.Incremental,
|
|
34
|
+
documentFormattingProvider: true,
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (this.service.settings.hasWorkspaceFolderCapability) {
|
|
39
|
+
result.capabilities.workspace = {
|
|
40
|
+
workspaceFolders: {
|
|
41
|
+
supported: true,
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
}
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
connection.workspace.onDidChangeWorkspaceFolders((_event) => {
|
|
46
|
-
connection.console.log("Workspace folder change event received.")
|
|
46
|
+
return result
|
|
47
47
|
})
|
|
48
|
-
}
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
connection.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
49
|
+
this.connection.onInitialized(() => {
|
|
50
|
+
if (this.service.settings.hasConfigurationCapability) {
|
|
51
|
+
// Register for all configuration changes.
|
|
52
|
+
this.connection.client.register(DidChangeConfigurationNotification.type, undefined)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (this.service.settings.hasWorkspaceFolderCapability) {
|
|
56
|
+
this.connection.workspace.onDidChangeWorkspaceFolders((_event) => {
|
|
57
|
+
this.connection.console.log("Workspace folder change event received.")
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
this.connection.client.register(DidChangeWatchedFilesNotification.type, {
|
|
62
|
+
watchers: [
|
|
63
|
+
{ globPattern: `**/**/*.html.erb` },
|
|
64
|
+
{ globPattern: `**/**/.herb-lsp/config.json` },
|
|
65
|
+
],
|
|
66
|
+
})
|
|
67
|
+
})
|
|
67
68
|
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
this.connection.onDidChangeConfiguration(async (change) => {
|
|
70
|
+
if (this.service.settings.hasConfigurationCapability) {
|
|
71
|
+
// Reset all cached document settings
|
|
72
|
+
this.service.settings.documentSettings.clear()
|
|
73
|
+
} else {
|
|
74
|
+
this.service.settings.globalSettings = (
|
|
75
|
+
(change.settings.languageServerHerb || this.service.settings.defaultSettings)
|
|
76
|
+
) as HerbSettings
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
await this.service.refresh()
|
|
80
|
+
})
|
|
70
81
|
|
|
71
|
-
connection.onDidOpenTextDocument((params) => {
|
|
72
|
-
|
|
73
|
-
const document = service.documentService.get(params.textDocument.uri)
|
|
82
|
+
this.connection.onDidOpenTextDocument(async (params) => {
|
|
83
|
+
const document = this.service.documentService.get(params.textDocument.uri)
|
|
74
84
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
})
|
|
85
|
+
if (document) {
|
|
86
|
+
await this.service.diagnostics.refreshDocument(document)
|
|
87
|
+
}
|
|
88
|
+
})
|
|
79
89
|
|
|
80
|
-
connection.onDidChangeWatchedFiles((params) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
90
|
+
this.connection.onDidChangeWatchedFiles((params) => {
|
|
91
|
+
params.changes.forEach(async (event) => {
|
|
92
|
+
if (event.uri.endsWith("/.herb-lsp/config.json")) {
|
|
93
|
+
await this.service.refreshConfig()
|
|
84
94
|
|
|
85
|
-
|
|
86
|
-
|
|
95
|
+
const documents = this.service.documentService.getAll()
|
|
96
|
+
await Promise.all(documents.map(document =>
|
|
97
|
+
this.service.diagnostics.refreshDocument(document)
|
|
98
|
+
))
|
|
99
|
+
}
|
|
87
100
|
})
|
|
88
|
-
}
|
|
89
|
-
})
|
|
90
|
-
})
|
|
101
|
+
})
|
|
91
102
|
|
|
92
|
-
|
|
93
|
-
|
|
103
|
+
this.connection.onDocumentFormatting((params: DocumentFormattingParams) => {
|
|
104
|
+
return this.service.formatting.formatDocument(params)
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
listen() {
|
|
109
|
+
this.connection.listen()
|
|
110
|
+
}
|
|
111
|
+
}
|
package/src/service.ts
CHANGED
|
@@ -1,29 +1,44 @@
|
|
|
1
1
|
import { Connection, InitializeParams } from "vscode-languageserver/node"
|
|
2
2
|
|
|
3
|
-
import { Settings } from "./settings"
|
|
3
|
+
import { Settings, HerbSettings } from "./settings"
|
|
4
4
|
import { DocumentService } from "./document_service"
|
|
5
5
|
import { Diagnostics } from "./diagnostics"
|
|
6
|
+
import { ParserService } from "./parser_service"
|
|
7
|
+
import { LinterService } from "./linter_service"
|
|
6
8
|
import { Config } from "./config"
|
|
7
9
|
import { Project } from "./project"
|
|
10
|
+
import { FormattingService } from "./formatting_service"
|
|
8
11
|
|
|
9
12
|
export class Service {
|
|
10
13
|
connection: Connection
|
|
11
14
|
settings: Settings
|
|
12
15
|
diagnostics: Diagnostics
|
|
13
16
|
documentService: DocumentService
|
|
17
|
+
parserService: ParserService
|
|
18
|
+
linterService: LinterService
|
|
14
19
|
project: Project
|
|
15
20
|
config?: Config
|
|
21
|
+
formatting: FormattingService
|
|
16
22
|
|
|
17
23
|
constructor(connection: Connection, params: InitializeParams) {
|
|
18
24
|
this.connection = connection
|
|
19
25
|
this.settings = new Settings(params, this.connection)
|
|
20
26
|
this.documentService = new DocumentService(this.connection)
|
|
21
27
|
this.project = new Project(connection, this.settings.projectPath.replace("file://", ""))
|
|
22
|
-
this.
|
|
28
|
+
this.parserService = new ParserService()
|
|
29
|
+
this.linterService = new LinterService(this.settings)
|
|
30
|
+
this.formatting = new FormattingService(this.connection, this.documentService.documents, this.project, this.settings)
|
|
31
|
+
this.diagnostics = new Diagnostics(this.connection, this.documentService, this.parserService, this.linterService)
|
|
32
|
+
|
|
33
|
+
// Initialize global settings from initialization options
|
|
34
|
+
if (params.initializationOptions) {
|
|
35
|
+
this.settings.globalSettings = params.initializationOptions as HerbSettings
|
|
36
|
+
}
|
|
23
37
|
}
|
|
24
38
|
|
|
25
39
|
async init() {
|
|
26
40
|
await this.project.initialize()
|
|
41
|
+
await this.formatting.initialize()
|
|
27
42
|
|
|
28
43
|
this.config = await Config.fromPathOrNew(this.project.projectPath)
|
|
29
44
|
|
|
@@ -34,18 +49,18 @@ export class Service {
|
|
|
34
49
|
|
|
35
50
|
// The content of a text document has changed. This event is emitted
|
|
36
51
|
// when the text document first opened or when its content has changed.
|
|
37
|
-
this.documentService.onDidChangeContent((change) => {
|
|
38
|
-
this.diagnostics.refreshDocument(change.document)
|
|
52
|
+
this.documentService.onDidChangeContent(async (change) => {
|
|
53
|
+
await this.diagnostics.refreshDocument(change.document)
|
|
39
54
|
})
|
|
40
55
|
}
|
|
41
56
|
|
|
42
57
|
async refresh() {
|
|
43
58
|
await this.project.refresh()
|
|
44
|
-
|
|
45
|
-
this.diagnostics.refreshAllDocuments()
|
|
59
|
+
await this.diagnostics.refreshAllDocuments()
|
|
46
60
|
}
|
|
47
61
|
|
|
48
62
|
async refreshConfig() {
|
|
49
63
|
this.config = await Config.fromPathOrNew(this.project.projectPath)
|
|
64
|
+
await this.formatting.refreshConfig()
|
|
50
65
|
}
|
|
51
66
|
}
|
package/src/settings.ts
CHANGED
|
@@ -1,12 +1,34 @@
|
|
|
1
1
|
import { ClientCapabilities, Connection, InitializeParams } from "vscode-languageserver/node"
|
|
2
|
+
import { defaultFormatOptions } from "@herb-tools/formatter"
|
|
2
3
|
|
|
3
|
-
export interface HerbSettings {
|
|
4
|
+
export interface HerbSettings {
|
|
5
|
+
trace?: {
|
|
6
|
+
server?: string
|
|
7
|
+
}
|
|
8
|
+
linter?: {
|
|
9
|
+
enabled?: boolean
|
|
10
|
+
}
|
|
11
|
+
formatter?: {
|
|
12
|
+
enabled?: boolean
|
|
13
|
+
indentWidth?: number
|
|
14
|
+
maxLineLength?: number
|
|
15
|
+
}
|
|
16
|
+
}
|
|
4
17
|
|
|
5
18
|
export class Settings {
|
|
6
19
|
// The global settings, used when the `workspace/configuration` request is not supported by the client.
|
|
7
20
|
// Please note that this is not the case when using this server with the client provided in this example
|
|
8
21
|
// but could happen with other clients.
|
|
9
|
-
defaultSettings: HerbSettings = {
|
|
22
|
+
defaultSettings: HerbSettings = {
|
|
23
|
+
linter: {
|
|
24
|
+
enabled: true
|
|
25
|
+
},
|
|
26
|
+
formatter: {
|
|
27
|
+
enabled: false,
|
|
28
|
+
indentWidth: defaultFormatOptions.indentWidth,
|
|
29
|
+
maxLineLength: defaultFormatOptions.maxLineLength
|
|
30
|
+
}
|
|
31
|
+
}
|
|
10
32
|
globalSettings: HerbSettings = this.defaultSettings
|
|
11
33
|
documentSettings: Map<string, Thenable<HerbSettings>> = new Map()
|
|
12
34
|
|