Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Log to LSP client #115

Merged
merged 1 commit into from
May 24, 2018
Merged

Log to LSP client #115

merged 1 commit into from
May 24, 2018

Conversation

bmulvihill
Copy link
Contributor

This PR will change the logging to log to the LSP client instead of to the scry.out tempfile.

I am opening the PR for discussion/ideas. I still have to write specs and such.

Currently the PR does the following

  • Adds LogMessageParams and MessageType to the protocol
  • Renames old MessageType to ProtocolMessage
  • Creates the concept of a Client which can be used to send messages to the LSP client
  • Allows Logger to be set

@faustinoaq
Copy link
Member

screenshot_20180507_204935

screenshot_20180507_205013

Thank you, Very useful 👏 👍 🎉

@faustinoaq faustinoaq added the wip label May 8, 2018
@faustinoaq
Copy link
Member

This is very nice, although, scry have some very verbose logs like this:

Log.logger.debug("Finished building the dependancy graph got these nodes:#{graph.each.to_a.map(&.first)}")

So, I suggest to review them and remove the extreme verbosity:

screenshot_20180421_195116

Otherwise the lsp-client/editor would freeze because too many logs 😅

sometimes scry generate MB of debug data:

screenshot_20180508_095151

Sometimes, even GB, see #67 by @bew

@bmulvihill
Copy link
Contributor Author

@faustinoaq Yes I noticed that as well. I can remove some of the more "verbose" logging if that is desirable or we could log that stuff a tempfile like we were doing (i.e. have two loggers, a scry logger and a client logger), but that might get confusing. I am not sure how useful some of these really big logs statements are 🤔

@faustinoaq
Copy link
Member

@bmulvihill Yeah, that may be confusing. I think we should cleanup logging and just keep client logger.

@@ -57,7 +57,6 @@ module Scry

def get_file(text_document : TextDocumentIdentifier)
filename = TextDocument.uri_to_filename(text_document.uri)
Log.logger.debug("@open_files: #{@open_files}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this one was the most verbose 👍

@faustinoaq
Copy link
Member

Hey @bmulvihill I already tested this and is very useful and works very nice

@crystal-lang-tools/scry Maybe we can add a log spec on a new PR, WDYT? 😅

@bmulvihill
Copy link
Contributor Author

@faustinoaq sorry I got sidetracked on that file bug last week when working on specs. I’ll try to wrap this up tomorrow

@bmulvihill bmulvihill force-pushed the log-message branch 2 times, most recently from c56878f to 89c4d6b Compare May 17, 2018 00:17
@bmulvihill
Copy link
Contributor Author

@crystal-lang-tools/scry @faustinoaq I removed some of the log calls, and added some specs. I am still not 100% happy w. this, but I am short on time lately. I would appreciate any feedback

@bmulvihill bmulvihill changed the title [WIP] Log to LSP client Log to LSP client May 17, 2018
src/scry/log.cr Outdated
logger = Logger.new(log_file)
logger.level = Logger::INFO
logger
logger = ClientLogger.new(Client.instance.io)
end

@@logger : Logger = initialize_logger
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a method anymore, you can directly use ClientLogger.new ...

src/scry/log.cr Outdated
logger = Logger.new(log_file)
logger.level = Logger::INFO
logger
logger = ClientLogger.new(Client.instance.io)
end

@@logger : Logger = initialize_logger

def self.logger
@@logger
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: class_getter logger does the same thing ;)

(or even class_property now that you also have a setter below)

@@ -0,0 +1,8 @@
module Scry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be Scry::Protocol ?

I just realized that (all?) the LSP protocol is not in a Protocol module, as I think it should, to properly see on usage when you're using a protocol type or not (that's important!).

This can be done later in another PR though!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm already working on that 👍

class Client
alias ClientMessage = Initialize | ResponseMessage | NotificationMessage | Nil

def self.instance(io : IO = STDOUT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a bit tricky if you want to use your own IO (i.e: in specs), you need to make sure that the first call to Client.instance has an IO, and you can't change the IO later once it's set.

I think it would be better to keep the Client.instance as a simple getter, and change the architecture: maybe Client doesn't even need to be a singleton?

@bew
Copy link
Contributor

bew commented May 17, 2018

As I said in one of the comment, I think Client should not be a singleton.

Here is a way to do it:

  • Store the client in ClientLogger, and use it in ClientLogger#write to send the log message.
  • Configure the logger in Scry.start, not as a default in log.cr. You'll also have to instantiate a Client with its IO before the logger init and pass that client to ClientLogger constructor.
  • And finally, remove the default io param to Client constructor, to force you to be explicit!

This way you never have to use a Client.instance method, you always have the current Client object to send things. And additionally, you can configure things easily, and repeatably (for specs).

Do you see what I mean?

@bmulvihill
Copy link
Contributor Author

I am also wondering if there is any use for the Log class anymore. I just left it in to maintain the interface, but it might not have much value anymore.

src/scry/log.cr Outdated
@closed = false
@mutex = Mutex.new
@io = @client.io
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you copy this constructor from Logger?
I would suggest to keep it simple, and use super to call the Logger's normal constructor.
E.g:

def initialize(@client : Client, level = Severity::INFO)
  super(@client.io, level)
end

I don't think we need the rest for now.

But as you like :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh yes, good call ;)

@bew
Copy link
Contributor

bew commented May 17, 2018

Hmm yeah Log is not useful as a class anymore, but we can keep it around as a module? So that you still have to do Log.logger.debug(...)

@faustinoaq
Copy link
Member

faustinoaq commented May 18, 2018

@bmulvihill Hi, I just tried latest changes and this feature still works fine 🎉

Although, I notices a new null on my logs on every request, Why? 😅

screenshot_20180517_220910

screenshot_20180517_220835

BTW, Do you know what happened with the initializer capabilities log we used to have? 😅

Edit:

With "initializer capabilities log" I mean the initializer message:

{ "jsonrpc": "2.0", "id": 1, "method": "initialize", "params": { "processId": 1, "rootPath": "<root-path-here>", "capabilities": {} , "trace": "off"}}

I think we used to log this as well.

Currently I can't see it on scry log 😅

@bmulvihill
Copy link
Contributor Author

@crystal-lang-tools/scry Made some adjustments, null should no longer be logged.

@faustinoaq faustinoaq self-requested a review May 23, 2018 19:39
@faustinoaq faustinoaq requested review from laginha87, bew and a team May 23, 2018 19:39
Copy link
Contributor

@bew bew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 😃

@bmulvihill note for later: next time can you make individual commits for new changes? For example you removed the null, by not making a commit for that change only, I have no idea what you did to remove it.

Copy link
Member

@faustinoaq faustinoaq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works like a charm! 👍

screenshot_20180523_203732

@faustinoaq faustinoaq removed the wip label May 24, 2018
@faustinoaq faustinoaq merged commit bf57569 into master May 24, 2018
@faustinoaq faustinoaq deleted the log-message branch May 24, 2018 11:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants