Skip to content

Commit 096d5ee

Browse files
committed
fix: [BUG] Formatter not getting recognized #15. Added formatterProvider to server capabilities, added languages section in package.json
1 parent 7c06e2d commit 096d5ee

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

client/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
"engines": {
1818
"vscode": "^1.85.0"
1919
},
20+
"activationEvents": [
21+
"onLanguage:ini"
22+
],
2023
"scripts": {
2124
"compile-test": "tsc -p tsconfig.test.json"
2225
},

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@
2929
],
3030
"main": "./client/out/extension",
3131
"contributes": {
32+
"languages": [
33+
{
34+
"id": "ini",
35+
"aliases": ["Ini", "INI"],
36+
"extensions": [
37+
".ini",
38+
".Ini",
39+
".INI"
40+
]
41+
}
42+
],
3243
"viewsContainers": {
3344
"activitybar": [
3445
{

server/src/server.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ connection.onInitialize((params: InitializeParams) => {
7474
const result: InitializeResult = {
7575
capabilities: {
7676
textDocumentSync: TextDocumentSyncKind.Full,
77+
documentFormattingProvider: true,
7778
// Tell the client that this server supports code completion.
7879
// definitionProvider: false, //true
7980
// hoverProvider: false, //true
@@ -113,16 +114,6 @@ connection.onInitialized(() => {
113114

114115
connection.client.register(DocumentFormattingRequest.type)
115116

116-
connection.onDocumentFormatting((_edits) => {
117-
const document = documents.get(_edits.textDocument.uri)
118-
if (!document) {
119-
console.log(`Document not found.`)
120-
return null
121-
}
122-
123-
return formatDocument(document, _edits.options.tabSize)
124-
})
125-
126117
connection.client.register(DidChangeConfigurationNotification.type)
127118

128119
if (hasConfigurationCapability) {
@@ -140,6 +131,16 @@ connection.onInitialized(() => {
140131
}
141132
});
142133

134+
connection.onDocumentFormatting((_edits) => {
135+
const document = documents.get(_edits.textDocument.uri)
136+
if (!document) {
137+
console.log(`Document not found.`)
138+
return null
139+
}
140+
141+
return formatDocument(document, _edits.options.tabSize)
142+
})
143+
143144
// connection.onDidOpenTextDocument((params: DidOpenTextDocumentParams) => {
144145
// const document = params.textDocument.text
145146
// documents.set(params.textDocument.uri, params.textDocument.text)

0 commit comments

Comments
 (0)