-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
36 lines (30 loc) · 908 Bytes
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const vscode = require('vscode')
module.exports.activate = () => {
vscode.workspace.onDidChangeTextDocument((event) => {
const changes = event.contentChanges[0]
if (
!changes ||
(event.document.languageId != 'luau' &&
event.document.languageId != 'lua')
) {
return
}
let start = changes.range.start
let end = changes.range.end
if (changes.text == '!') {
start = new vscode.Position(start.line, start.character)
end = new vscode.Position(end.line, end.character + 2)
} else if (changes.text == '=' && start.character != 0) {
start = new vscode.Position(start.line, start.character - 1)
end = new vscode.Position(end.line, end.character + 1)
} else {
return
}
const range = new vscode.Range(start, end)
if (event.document.getText(range) == '!=') {
vscode.window.activeTextEditor.edit((builder) => {
builder.replace(range, '~=')
})
}
})
}