|
| 1 | +local lclient = require 'tclient.lclient' |
| 2 | +local util = require 'utility' |
| 3 | +local ws = require 'workspace' |
| 4 | +local files = require 'files' |
| 5 | +local furi = require 'file-uri' |
| 6 | +local fs = require 'bee.filesystem' |
| 7 | + |
| 8 | +local libraryPath = LOGPATH .. '/load-library' |
| 9 | +local libraryFilePath = LOGPATH .. '/load-library/library-file.lua' |
| 10 | + |
| 11 | +---@async |
| 12 | +lclient():start(function (client) |
| 13 | + client:registerFakers() |
| 14 | + |
| 15 | + client:register('workspace/configuration', function () |
| 16 | + return { |
| 17 | + { |
| 18 | + ['workspace.library'] = { libraryPath } |
| 19 | + }, |
| 20 | + } |
| 21 | + end) |
| 22 | + |
| 23 | + fs.create_directories(fs.path(libraryPath)) |
| 24 | + if not fs.exists(fs.path(libraryFilePath)) then |
| 25 | + util.saveFile(libraryFilePath, 'LIBRARY_FILE = true') |
| 26 | + end |
| 27 | + |
| 28 | + client:initialize() |
| 29 | + |
| 30 | + client:notify('textDocument/didOpen', { |
| 31 | + textDocument = { |
| 32 | + uri = furi.encode('abc/1.lua'), |
| 33 | + languageId = 'lua', |
| 34 | + version = 0, |
| 35 | + text = [[ |
| 36 | +require 'library-file' |
| 37 | +print(LIBRARY_FILE) |
| 38 | +]] |
| 39 | + } |
| 40 | + }) |
| 41 | + |
| 42 | + ws.awaitReady() |
| 43 | + |
| 44 | + local locations = client:awaitRequest('textDocument/definition', { |
| 45 | + textDocument = { uri = furi.encode('abc/1.lua') }, |
| 46 | + position = { line = 0, character = 10 }, |
| 47 | + }) |
| 48 | + |
| 49 | + assert(util.equal(locations, { |
| 50 | + { |
| 51 | + uri = furi.encode(libraryFilePath), |
| 52 | + range = { |
| 53 | + start = { line = 0, character = 0 }, |
| 54 | + ['end'] = { line = 0, character = 0 }, |
| 55 | + } |
| 56 | + } |
| 57 | + })) |
| 58 | +end) |
0 commit comments