From 53bf979617f696f51ae8467a500082d8772293f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gild=C3=A9ric=20DERUETTE?= Date: Thu, 12 Dec 2024 13:52:55 +0100 Subject: [PATCH] [VSCode] Fix Exception --- TopModel.LanguageServer/CompletionHandler.cs | 27 +++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/TopModel.LanguageServer/CompletionHandler.cs b/TopModel.LanguageServer/CompletionHandler.cs index 9c7a6e10..923c4770 100644 --- a/TopModel.LanguageServer/CompletionHandler.cs +++ b/TopModel.LanguageServer/CompletionHandler.cs @@ -4,7 +4,15 @@ using OmniSharp.Extensions.LanguageServer.Protocol.Server; using TopModel.Core; using TopModel.Core.FileModel; - +using System.Reflection; +using System.Text; +using NJsonSchema; +using NJsonSchema.Validation; +using TopModel.Utils; +using YamlDotNet.Core; +using YamlDotNet.Core.Events; +using YamlDotNet.Serialization; +using YamlDotNet.Serialization.NamingConventions; namespace TopModel.LanguageServer; public class CompletionHandler : CompletionHandlerBase @@ -67,7 +75,6 @@ public override Task Handle(CompletionParams request, Cancellati var currentKey = GetCurrentKey(request).Key; var parentKey = GetParentKey(request).Key; var useIndex = GetUseIndex(file, text); - if (parentKey == "asDomains" && currentLine[..reqChar].Contains(':') || currentKey == "domain" || parentKey == "domain" && currentLine[..reqChar].Contains("name: ") @@ -537,7 +544,7 @@ private int GetIndentLevel(string line) end++; } - return (start + 1, end - 1); + return (Math.Min(start + 1, lineNumber), Math.Max(end - 1, lineNumber)); } private (string Key, int Line, int End, bool IsKey) GetParentKey(CompletionParams request) @@ -589,6 +596,20 @@ private int GetIndentLevel(string line) return GetObjectRange(text, start); } + private string[] GetYaml(CompletionParams request) + { + var text = _fileCache.GetFile(request.TextDocument.Uri.GetFileSystemPath()); + var start = request.Position.Line; + var currentLine = text.ElementAtOrDefault(request.Position.Line) ?? string.Empty; + while (!currentLine.StartsWith("---") && start > 0) + { + start--; + currentLine = text.ElementAtOrDefault(start) ?? string.Empty; + } + + return text[start..request.Position.Line]; + } + private (string Object, int Line) GetRootObject(CompletionParams request) { var text = _fileCache.GetFile(request.TextDocument.Uri.GetFileSystemPath());