Skip to content

Commit

Permalink
Sync with geany-lsp
Browse files Browse the repository at this point in the history
  • Loading branch information
techee committed Dec 19, 2024
1 parent 780de1c commit 911edf4
Show file tree
Hide file tree
Showing 6 changed files with 359 additions and 89 deletions.
2 changes: 2 additions & 0 deletions lsp/src/lsp-autocomplete.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ static guint get_ident_prefixlen(const gchar *word_chars, GeanyDocument *doc, gi
if (!strchr(word_chars, c))
break;
}
else
break;
num++;
pos = new_pos;
}
Expand Down
28 changes: 15 additions & 13 deletions lsp/src/lsp-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,8 @@ static void initialize_cb(GVariant *return_value, GError *error, gpointer user_d
}
else
{
msgwin_status_add(_("LSP initialize request failed for LSP server, terminating %s"), s->config.cmd);
msgwin_status_add(_("Initialize request failed for LSP server %s: %s"), s->config.cmd, error->message);
msgwin_status_add(_("Force terminating %s"), s->config.cmd);

// force exit the server - since the handshake didn't perform, the
// server may be in some strange state and normal "exit" may not work
Expand Down Expand Up @@ -808,16 +809,23 @@ static GKeyFile *read_keyfile(const gchar *config_file)
}


static void stderr_cb(GString *string, GIOCondition condition, gpointer data)
{
LspServer *srv = data;

if (srv->config.show_server_stderr)
fprintf(stderr, "%s", string->str);
}


static void start_lsp_server(LspServer *server)
{
GInputStream *input_stream;
GOutputStream *output_stream;
GError *error = NULL;
gint stdin_fd = -1;
gint stdout_fd = -1;
gint stderr_fd = -1;
gboolean success;
GSource *source;
GString *cmd = g_string_new(server->config.cmd);

#ifdef G_OS_UNIX
Expand All @@ -832,11 +840,10 @@ static void start_lsp_server(LspServer *server)

msgwin_status_add(_("Starting LSP server %s"), cmd->str);

success = lsp_spawn_async_with_pipes(NULL, cmd->str, NULL,
server->config.env, &server->pid,
&stdin_fd, &stdout_fd,
server->config.show_server_stderr ? NULL : &stderr_fd,
&error);
success = lsp_spawn_with_pipes_and_stderr_callback(NULL, cmd->str, NULL,
server->config.env,
&stdin_fd, &stdout_fd, stderr_cb, server, 0,
process_stopped, server, &server->pid, &error);

if (!success)
{
Expand All @@ -847,11 +854,6 @@ static void start_lsp_server(LspServer *server)
return;
}

source = g_child_watch_source_new(server->pid);
g_source_set_callback(source, (GSourceFunc) (void(*)(void)) (GChildWatchFunc) process_stopped, server, NULL);
g_source_attach(source, NULL);
g_source_unref(source);

#ifdef G_OS_UNIX
input_stream = g_unix_input_stream_new(stdout_fd, TRUE);
output_stream = g_unix_output_stream_new(stdin_fd, TRUE);
Expand Down
36 changes: 0 additions & 36 deletions lsp/src/spawn/lspunixinputstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,47 +296,13 @@ lsp_unix_input_stream_read (GInputStream *stream,
{
LspUnixInputStream *unix_stream;
gssize res = -1;
GPollFD poll_fds[2];
int nfds;
int poll_ret;

unix_stream = LSP_UNIX_INPUT_STREAM (stream);

poll_fds[0].fd = unix_stream->priv->fd;
poll_fds[0].events = G_IO_IN;
if (unix_stream->priv->can_poll &&
g_cancellable_make_pollfd (cancellable, &poll_fds[1]))
nfds = 2;
else
nfds = 1;

while (1)
{
int errsv;

poll_fds[0].revents = poll_fds[1].revents = 0;
do
{
poll_ret = g_poll (poll_fds, nfds, -1);
errsv = errno;
}
while (poll_ret == -1 && errsv == EINTR);

if (poll_ret == -1)
{
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errsv),
"Error reading from file descriptor: %s",
g_strerror (errsv));
break;
}

if (g_cancellable_set_error_if_cancelled (cancellable, error))
break;

if (!poll_fds[0].revents)
continue;

res = read (unix_stream->priv->fd, buffer, count);
if (res == -1)
{
Expand All @@ -354,8 +320,6 @@ lsp_unix_input_stream_read (GInputStream *stream,
break;
}

if (nfds == 2)
g_cancellable_release_fd (cancellable);
return res;
}

Expand Down
36 changes: 0 additions & 36 deletions lsp/src/spawn/lspunixoutputstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,47 +282,13 @@ lsp_unix_output_stream_write (GOutputStream *stream,
{
LspUnixOutputStream *unix_stream;
gssize res = -1;
GPollFD poll_fds[2];
int nfds = 0;
int poll_ret;

unix_stream = LSP_UNIX_OUTPUT_STREAM (stream);

poll_fds[0].fd = unix_stream->priv->fd;
poll_fds[0].events = G_IO_OUT;
nfds++;

if (unix_stream->priv->can_poll &&
g_cancellable_make_pollfd (cancellable, &poll_fds[1]))
nfds++;

while (1)
{
int errsv;

poll_fds[0].revents = poll_fds[1].revents = 0;
do
{
poll_ret = g_poll (poll_fds, nfds, -1);
errsv = errno;
}
while (poll_ret == -1 && errsv == EINTR);

if (poll_ret == -1)
{
g_set_error (error, G_IO_ERROR,
g_io_error_from_errno (errsv),
"Error writing to file descriptor: %s",
g_strerror (errsv));
break;
}

if (g_cancellable_set_error_if_cancelled (cancellable, error))
break;

if (!poll_fds[0].revents)
continue;

res = write (unix_stream->priv->fd, buffer, count);
errsv = errno;
if (res == -1)
Expand All @@ -339,8 +305,6 @@ lsp_unix_output_stream_write (GOutputStream *stream,
break;
}

if (nfds == 2)
g_cancellable_release_fd (cancellable);
return res;
}

Expand Down
Loading

0 comments on commit 911edf4

Please sign in to comment.