From 1bd1416c89f92f637ca5e22c94b3479f8d32f2d7 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Tue, 27 Aug 2024 22:08:31 +0200 Subject: make the message handling functions methods of the lspc object Move the logging code into its own module and export the default logger. Other modules can use the logger exported in the lspc table. --- lspc.lua | 52 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) (limited to 'lspc.lua') diff --git a/lspc.lua b/lspc.lua index b6ea7e3..5ce9000 100644 --- a/lspc.lua +++ b/lspc.lua @@ -1,20 +1,12 @@ --- Copyright (c) 2021-2023 Florian Fischer. All rights reserved. --- --- This file is part of vis-lspc. --- --- vis-lspc is free software: you can redistribute it and/or modify it under the --- terms of the GNU General Public License as published by the Free Software --- Foundation, either version 3 of the License, or (at your option) any later --- version. --- --- vis-lspc is distributed in the hope that it will be useful, but WITHOUT ANY --- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS --- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. --- --- You should have received a copy of the GNU General Public License along with --- vis-lspc found in the LICENSE file. If not, see . --- --- State of our language server client +--- State and methods of the language server client. +-- This module table is returned when requiring the vis-lspc plugin. +-- @module lspc +-- @author Florian Fischer +-- @license GPL-3 +-- @copyright Florian Fischer 2021-2024 +--- Initial state of the client. +-- This includes the default configuration that can be modified in +-- your visrc.lua file. local lspc = { -- mapping language server names to their state tables running = {}, @@ -110,4 +102,30 @@ local client_capabilites = { lspc.client_capabilites = client_capabilites +local Lspc = {} + +--- Log a message. +-- @string: the message to log +function Lspc:log(msg) + self.logger:log(msg) +end + +--- Present a warning to the user. +-- @string: the warning message +function Lspc:warn(msg) + local warning = 'LSPC Warning: ' .. msg + self.logger:log(warning) + vis:info(warning) +end + +--- Present an error to the user. +-- @string: the error message +function Lspc:err(msg) + local warning = 'LSPC Error: ' .. msg + self.logger:log(warning) + vis:info(warning) +end + +setmetatable(lspc, {__index = Lspc}) + return lspc -- cgit v1.2.3