|
| 1 | +local lclient = require 'lclient' |
| 2 | +local util = require 'utility' |
| 3 | +local ws = require 'workspace' |
| 4 | +local jsonc = require 'jsonc' |
| 5 | +local jsonb = require 'json-beautify' |
| 6 | +local client = require 'client' |
| 7 | +local provider = require 'provider' |
| 8 | +local json = require 'json' |
| 9 | + |
| 10 | +local configPath = LOGPATH .. '/modify-luarc.json' |
| 11 | + |
| 12 | +---@async |
| 13 | +lclient():start(function (languageClient) |
| 14 | + languageClient:registerFakers() |
| 15 | + |
| 16 | + CONFIGPATH = configPath |
| 17 | + |
| 18 | + languageClient:initialize() |
| 19 | + |
| 20 | + ws.awaitReady() |
| 21 | + |
| 22 | + ------------------------------- |
| 23 | + |
| 24 | + util.saveFile(configPath, jsonb.beautify { |
| 25 | + ['xxxx'] = 1, -- TODO: bug of json-edit, can not be an empty json |
| 26 | + }) |
| 27 | + |
| 28 | + provider.updateConfig() |
| 29 | + |
| 30 | + client.setConfig({ |
| 31 | + { |
| 32 | + action = 'set', |
| 33 | + key = 'Lua.runtime.version', |
| 34 | + value = 'LuaJIT', |
| 35 | + } |
| 36 | + }) |
| 37 | + |
| 38 | + assert(util.equal(jsonc.decode_jsonc(util.loadFile(configPath)), { |
| 39 | + ['xxxx'] = 1, |
| 40 | + ['Lua.runtime.version'] = 'LuaJIT', |
| 41 | + })) |
| 42 | + |
| 43 | + ------------------------------- |
| 44 | + |
| 45 | + util.saveFile(configPath, jsonb.beautify { |
| 46 | + ['xxxx'] = 1, -- TODO: bug of json-edit, can not be an empty json |
| 47 | + }) |
| 48 | + |
| 49 | + provider.updateConfig() |
| 50 | + |
| 51 | + client.setConfig({ |
| 52 | + { |
| 53 | + action = 'add', |
| 54 | + key = 'Lua.diagnostics.disable', |
| 55 | + value = 'undefined-global', |
| 56 | + } |
| 57 | + }) |
| 58 | + |
| 59 | + assert(util.equal(jsonc.decode_jsonc(util.loadFile(configPath)), { |
| 60 | + ['xxxx'] = 1, |
| 61 | + ['Lua.diagnostics.disable'] = { |
| 62 | + 'undefined-global', |
| 63 | + } |
| 64 | + })) |
| 65 | + |
| 66 | + ------------------------------- |
| 67 | + |
| 68 | + util.saveFile(configPath, jsonb.beautify { |
| 69 | + ['Lua.diagnostics.disable'] = {} |
| 70 | + }) |
| 71 | + |
| 72 | + provider.updateConfig() |
| 73 | + |
| 74 | + client.setConfig({ |
| 75 | + { |
| 76 | + action = 'add', |
| 77 | + key = 'Lua.diagnostics.disable', |
| 78 | + value = 'undefined-global', |
| 79 | + } |
| 80 | + }) |
| 81 | + |
| 82 | + assert(util.equal(jsonc.decode_jsonc(util.loadFile(configPath)), { |
| 83 | + ['Lua.diagnostics.disable'] = { |
| 84 | + 'undefined-global', |
| 85 | + } |
| 86 | + })) |
| 87 | + |
| 88 | + ------------------------------- |
| 89 | + |
| 90 | + util.saveFile(configPath, jsonb.beautify { |
| 91 | + ['Lua.diagnostics.disable'] = { |
| 92 | + 'unused-local' |
| 93 | + } |
| 94 | + }) |
| 95 | + |
| 96 | + provider.updateConfig() |
| 97 | + |
| 98 | + client.setConfig({ |
| 99 | + { |
| 100 | + action = 'add', |
| 101 | + key = 'Lua.diagnostics.disable', |
| 102 | + value = 'undefined-global', |
| 103 | + } |
| 104 | + }) |
| 105 | + |
| 106 | + assert(util.equal(jsonc.decode_jsonc(util.loadFile(configPath)), { |
| 107 | + ['Lua.diagnostics.disable'] = { |
| 108 | + 'unused-local', |
| 109 | + 'undefined-global', |
| 110 | + } |
| 111 | + })) |
| 112 | + |
| 113 | + ------------------------------- |
| 114 | + |
| 115 | + util.saveFile(configPath, jsonb.beautify { |
| 116 | + ['xxxx'] = 1, -- TODO: bug of json-edit, can not be an empty json |
| 117 | + }) |
| 118 | + |
| 119 | + provider.updateConfig() |
| 120 | + |
| 121 | + client.setConfig({ |
| 122 | + { |
| 123 | + action = 'prop', |
| 124 | + key = 'Lua.runtime.special', |
| 125 | + prop = 'include', |
| 126 | + value = 'require', |
| 127 | + } |
| 128 | + }) |
| 129 | + |
| 130 | + assert(util.equal(jsonc.decode_jsonc(util.loadFile(configPath)), { |
| 131 | + ['xxxx'] = 1, |
| 132 | + ['Lua.runtime.special'] = { |
| 133 | + ['include'] = 'require', |
| 134 | + } |
| 135 | + })) |
| 136 | + |
| 137 | + ------------------------------- |
| 138 | + |
| 139 | + util.saveFile(configPath, jsonb.beautify { |
| 140 | + ['Lua.runtime.special'] = json.createEmptyObject() |
| 141 | + }) |
| 142 | + |
| 143 | + provider.updateConfig() |
| 144 | + |
| 145 | + client.setConfig({ |
| 146 | + { |
| 147 | + action = 'prop', |
| 148 | + key = 'Lua.runtime.special', |
| 149 | + prop = 'include', |
| 150 | + value = 'require', |
| 151 | + } |
| 152 | + }) |
| 153 | + |
| 154 | + -- TODO: bug of json-edit, can not be an empty json |
| 155 | + -- assert(util.equal(jsonc.decode_jsonc(util.loadFile(configPath)), { |
| 156 | + -- ['Lua.runtime.special'] = { |
| 157 | + -- ['include'] = 'require', |
| 158 | + -- } |
| 159 | + -- })) |
| 160 | + |
| 161 | + ------------------------------- |
| 162 | + |
| 163 | + util.saveFile(configPath, jsonb.beautify { |
| 164 | + ['Lua.runtime.special'] = { |
| 165 | + ['import'] = 'require', |
| 166 | + } |
| 167 | + }) |
| 168 | + |
| 169 | + provider.updateConfig() |
| 170 | + |
| 171 | + client.setConfig({ |
| 172 | + { |
| 173 | + action = 'prop', |
| 174 | + key = 'Lua.runtime.special', |
| 175 | + prop = 'include', |
| 176 | + value = 'require', |
| 177 | + } |
| 178 | + }) |
| 179 | + |
| 180 | + assert(util.equal(jsonc.decode_jsonc(util.loadFile(configPath)), { |
| 181 | + ['Lua.runtime.special'] = { |
| 182 | + ['import'] = 'require', |
| 183 | + ['include'] = 'require', |
| 184 | + } |
| 185 | + })) |
| 186 | + |
| 187 | +end) |
0 commit comments