Skip to content

Commit

Permalink
style(): format codebase with dotnet-format (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
smolck authored Sep 8, 2021
1 parent 325d971 commit d22b443
Show file tree
Hide file tree
Showing 25 changed files with 238 additions and 237 deletions.
118 changes: 59 additions & 59 deletions src/NvimClient.API/NvimAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private static Stream GetStreamFromServerAddress(string serverAddress)
var match = Regex.Match(serverAddress,
@"\\\\(?'serverName'[^\\]+)\\pipe\\(?'pipeName'[^\\]+)");
var serverName = match.Groups["serverName"].Value;
var pipeName = match.Groups["pipeName"].Value;
var pipeName = match.Groups["pipeName"].Value;
var pipeStream = new NamedPipeClientStream(serverName, pipeName,
PipeDirection.InOut, PipeOptions.Asynchronous);
pipeStream.Connect();
Expand Down Expand Up @@ -119,10 +119,10 @@ public NvimAPI(Stream inputStream, Stream outputStream)
{
var context = new SerializationContext();
context.Serializers.Register(new NvimMessageSerializer(context));
_serializer = MessagePackSerializer.Get<NvimMessage>(context);
_inputStream = inputStream;
_serializer = MessagePackSerializer.Get<NvimMessage>(context);
_inputStream = inputStream;
_outputStream = outputStream;
_messageQueue = new BlockingCollection<NvimMessage>();
_messageQueue = new BlockingCollection<NvimMessage>();
_pendingRequests = new ConcurrentDictionary<long, PendingRequest>();
_handlers = new ConcurrentDictionary<string, NvimHandler>();

Expand All @@ -131,10 +131,10 @@ public NvimAPI(Stream inputStream, Stream outputStream)
}

public void RegisterHandler(string name, Func<object[], object> handler) =>
RegisterHandler(name, (Delegate) handler);
RegisterHandler(name, (Delegate)handler);

public void RegisterHandler(string name, Action<object[]> handler) =>
RegisterHandler(name, (Delegate) handler);
RegisterHandler(name, (Delegate)handler);

public void RegisterHandler(string name,
Func<object[], Task<object>> handler) => RegisterHandler(name,
Expand Down Expand Up @@ -178,10 +178,10 @@ private void RegisterHandler(string name, NvimHandler handler)
private void CallHandlerAndSendResponse(uint requestId, Delegate handler,
object[] args)
{
var response = new NvimResponse {MessageId = requestId};
var response = new NvimResponse { MessageId = requestId };
try
{
var result = handler.DynamicInvoke(new object[] {args});
var result = handler.DynamicInvoke(new object[] { args });
response.Result = ConvertToMessagePackObject(result);
}
catch (Exception exception)
Expand All @@ -197,11 +197,11 @@ internal void SendResponse(NvimUnhandledRequestEventArgs args, object result,
object error)
{
var response = new NvimResponse
{
MessageId = args.RequestId,
Result = ConvertToMessagePackObject(result),
Error = ConvertToMessagePackObject(error)
};
{
MessageId = args.RequestId,
Result = ConvertToMessagePackObject(result),
Error = ConvertToMessagePackObject(error)
};
_messageQueue.Add(response);
}

Expand All @@ -223,15 +223,15 @@ private Task<TResult> SendAndReceive<TResult>(NvimRequest request)
var result = ConvertFromMessagePackObject(response.Result);
if (typeof(TResult).IsArray)
{
var objectArray = (object[]) result;
var objectArray = (object[])result;
var resultArray = Array.CreateInstance(
typeof(TResult).GetElementType(),
objectArray.Length);
Array.Copy(objectArray, resultArray, resultArray.Length);
return (TResult) (object) resultArray;
return (TResult)(object)resultArray;
}
return (TResult) result;
return (TResult)result;
});
}

Expand Down Expand Up @@ -267,56 +267,56 @@ async void Receive()
switch (message)
{
case NvimNotification notification:
{
if (notification.Method == "redraw")
{
var uiEvents = notification.Arguments.AsEnumerable().SelectMany(
uiEvent =>
if (notification.Method == "redraw")
{
var uiEvents = notification.Arguments.AsEnumerable().SelectMany(
uiEvent =>
{
var data = uiEvent.AsList();
var name = data.First().AsString();
return data.Select(args => new { Name = name, Args = args })
.Skip(1);
});
foreach (var uiEvent in uiEvents)
{
var data = uiEvent.AsList();
var name = data.First().AsString();
return data.Select(args => new {Name = name, Args = args})
.Skip(1);
});
foreach (var uiEvent in uiEvents)
CallUIEventHandler(uiEvent.Name,
(object[])ConvertFromMessagePackObject(uiEvent.Args));
}
}

var arguments =
(object[])ConvertFromMessagePackObject(notification.Arguments);
if (_handlers.TryGetValue(notification.Method, out var handler))
{
CallUIEventHandler(uiEvent.Name,
(object[]) ConvertFromMessagePackObject(uiEvent.Args));
handler(null, arguments);
}
else
{
OnUnhandledNotification?.Invoke(this,
new NvimUnhandledNotificationEventArgs(notification.Method,
arguments));
}
}

var arguments =
(object[]) ConvertFromMessagePackObject(notification.Arguments);
if (_handlers.TryGetValue(notification.Method, out var handler))
{
handler(null, arguments);
break;
}
else
{
OnUnhandledNotification?.Invoke(this,
new NvimUnhandledNotificationEventArgs(notification.Method,
arguments));
}

break;
}
case NvimRequest request:
{
var arguments =
(object[]) ConvertFromMessagePackObject(request.Arguments);
if (_handlers.TryGetValue(request.Method, out var handler))
{
handler(request.MessageId, arguments);
}
else
{
OnUnhandledRequest?.Invoke(this,
new NvimUnhandledRequestEventArgs(this, request.MessageId,
request.Method, arguments));
}
var arguments =
(object[])ConvertFromMessagePackObject(request.Arguments);
if (_handlers.TryGetValue(request.Method, out var handler))
{
handler(request.MessageId, arguments);
}
else
{
OnUnhandledRequest?.Invoke(this,
new NvimUnhandledRequestEventArgs(this, request.MessageId,
request.Method, arguments));
}

break;
}
break;
}
case NvimResponse response:
if (!_pendingRequests.TryRemove(response.MessageId,
out var pendingRequest))
Expand All @@ -343,7 +343,7 @@ private class PendingRequest
{
private readonly TimeSpan _responseTimeout = TimeSpan.FromSeconds(10);
private readonly ManualResetEvent _receivedResponseEvent;
private NvimResponse _response;
private NvimResponse _response;

internal PendingRequest() =>
_receivedResponseEvent = new ManualResetEvent(false);
Expand All @@ -366,7 +366,7 @@ void RegisterResponseEvent(TimeSpan timeout) =>
else
{
taskCompletionSource.SetResult(
((PendingRequest) state)._response);
((PendingRequest)state)._response);
}
},
this, timeout, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public class NvimAutocmdAttribute : Attribute
{
public NvimAutocmdAttribute(string name) => Name = name;

public string Name { get; set; }
public string Group { get; set; }
public bool AllowNested { get; set; }
public string Pattern { get; set; }
public string Name { get; set; }
public string Group { get; set; }
public bool AllowNested { get; set; }
public string Pattern { get; set; }
}
}
16 changes: 8 additions & 8 deletions src/NvimClient.API/NvimPlugin/Attributes/NvimCommandAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ namespace NvimClient.API.NvimPlugin.Attributes
[AttributeUsage(AttributeTargets.Method)]
public class NvimCommandAttribute : Attribute
{
public string Addr { get; set; }
public string Addr { get; set; }
public string Complete { get; set; }
public long Count { get; set; }
public string Eval { get; set; }
public string Range { get; set; }
public bool Register { get; set; }
public string NArgs { get; set; }
public string Name { get; set; }
public bool Bar { get; set; }
public long Count { get; set; }
public string Eval { get; set; }
public string Range { get; set; }
public bool Register { get; set; }
public string NArgs { get; set; }
public string Name { get; set; }
public bool Bar { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace NvimClient.API.NvimPlugin.Attributes
[AttributeUsage(AttributeTargets.Method)]
public class NvimFunctionAttribute : Attribute
{
public string Name { get; set; }
public string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ namespace NvimClient.API.NvimPlugin.Attributes
[AttributeUsage(AttributeTargets.Class)]
public class NvimPluginAttribute : Attribute
{
public string Name { get; set; }
public string Name { get; set; }
public string Version { get; set; }
public string Website { get; set; }
public string License { get; set; }
public string Logo { get; set; }
public string Logo { get; set; }
}
}
12 changes: 6 additions & 6 deletions src/NvimClient.API/NvimPlugin/NvimPluginAutoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public NvimPluginAutocmd(MethodInfo method, string pluginPath,
{
argumentConverters.Add(
nvimArg => evalParameterIndices.Zip(
(object[]) nvimArg, (index, arg) =>
new PluginArgument
{
Value = arg,
Index = index
})
(object[])nvimArg, (index, arg) =>
new PluginArgument
{
Value = arg,
Index = index
})
);
}

Expand Down
22 changes: 11 additions & 11 deletions src/NvimClient.API/NvimPlugin/NvimPluginCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public NvimPluginCommand(MethodInfo method, string pluginPath,
{
argumentConverters.Add(arg =>
{
var range = ((object[]) arg).Cast<long>().ToArray();
var range = ((object[])arg).Cast<long>().ToArray();
return new[]
{
new PluginArgument
Expand Down Expand Up @@ -149,24 +149,24 @@ public NvimPluginCommand(MethodInfo method, string pluginPath,
{
argumentConverters.Add(
nvimArg => evalParameterIndices.Zip(
(object[]) nvimArg, (index, arg) =>
new PluginArgument
{
Value = arg,
Index = index
})
(object[])nvimArg, (index, arg) =>
new PluginArgument
{
Value = arg,
Index = index
})
);
}

ArgumentConverters = argumentConverters;
Attribute = attribute;
}

private int? BangParameterIndex { get; set; }
private int? CountParameterIndex { get; set; }
private int? RangeParameterIndex { get; set; }
private int? BangParameterIndex { get; set; }
private int? CountParameterIndex { get; set; }
private int? RangeParameterIndex { get; set; }
private int? RegisterParameterIndex { get; set; }
private NvimCommandAttribute Attribute { get; }
private NvimCommandAttribute Attribute { get; }

public override string HandlerName => $"{PluginPath}:command:{Name}";

Expand Down
24 changes: 12 additions & 12 deletions src/NvimClient.API/NvimPlugin/NvimPluginExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public abstract class NvimPluginExport
protected NvimPluginExport(string name, MethodInfo method,
string pluginPath, object pluginInstance)
{
Name = name;
Method = method;
PluginPath = pluginPath;
Name = name;
Method = method;
PluginPath = pluginPath;
PluginInstance = pluginInstance;
Sync = method.GetCustomAttribute<AsyncStateMachineAttribute>() == null
&& method.ReturnType != typeof(Task)
Expand All @@ -31,12 +31,12 @@ protected IReadOnlyCollection<ArgumentConverter> ArgumentConverters
set;
}

internal bool Sync { get; }
public abstract string HandlerName { get; }
protected string PluginPath { get; }
private object PluginInstance { get; }
public MethodInfo Method { get; }
public string Name { get; }
internal bool Sync { get; }
public abstract string HandlerName { get; }
protected string PluginPath { get; }
private object PluginInstance { get; }
public MethodInfo Method { get; }
public string Name { get; }

public Func<object[], object> Handler =>
args => Method.Invoke(PluginInstance,
Expand Down Expand Up @@ -83,8 +83,8 @@ protected void VisitParameters(
.Select((param, index) =>
new
{
Index = index,
Type = param.ParameterType,
Index = index,
Type = param.ParameterType,
Attributes = param.GetCustomAttributes()
}))
{
Expand Down Expand Up @@ -118,7 +118,7 @@ protected void VisitParameters(

protected struct PluginArgument
{
public int Index { get; set; }
public int Index { get; set; }
public object Value { get; set; }
}

Expand Down
Loading

0 comments on commit d22b443

Please sign in to comment.