Skip to content

Commit

Permalink
Project import generated by Copybara.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 81d36f76344f2948e8a105a1413688359c952496
  • Loading branch information
Copybara Bot authored and fortenforge committed Feb 21, 2024
1 parent f9f3573 commit e90a001
Show file tree
Hide file tree
Showing 11 changed files with 888 additions and 945 deletions.
2 changes: 1 addition & 1 deletion CodeiumVS/CodeiumVS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
4 changes: 2 additions & 2 deletions CodeiumVS/LanguageServer/LanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace CodeiumVS;
public class LanguageServer
{
private string _languageServerURL;
private string _languageServerVersion = "1.6.22";
private string _languageServerVersion = "1.6.38";

private int _port = 0;
private Process _process;
Expand All @@ -48,7 +48,7 @@ public async Task InitializeAsync()
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

string ideVersion = "17.0", locale = "en-US";
string ideVersion = "1.6.38";

try
{
Expand Down
6 changes: 4 additions & 2 deletions CodeiumVS/SettingsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public bool EnableLanguageServerProxy

[Category("Codeium")]
[DisplayName("Enable Codeium Indexing")]
[Description("Allows Codeium to index your current repository and provide better chat and autocomplete responses based on relevant parts of your codebase. Requires restart.")]
[Description(
"Allows Codeium to index your current repository and provide better chat and autocomplete responses based on relevant parts of your codebase. Requires restart.")]
public bool EnableIndexing
{
get {
Expand All @@ -111,7 +112,8 @@ public bool EnableIndexing

[Category("Codeium")]
[DisplayName("Indexing Max Workspace Size (File Count)")]
[Description("If indexing is enabled, we will only attempt to index workspaces that have up to this many files. This file count ignores .gitignore and binary files.")]
[Description(
"If indexing is enabled, we will only attempt to index workspaces that have up to this many files. This file count ignores .gitignore and binary files.")]
public int IndexingMaxWorkspaceSize
{
get {
Expand Down
167 changes: 84 additions & 83 deletions CodeiumVS/SuggestionUI/InlineGreyTextTagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,105 +18,106 @@

namespace CodeiumVS
{
internal class InlineGreyTextTagger : ITagger<IntraTextAdornmentTag>
{
protected readonly IWpfTextView view;
protected SnapshotSpan currentSpan;
private Brush greyBrush;
private StackPanel stackPanel;
public event EventHandler<SnapshotSpanEventArgs> TagsChanged;
internal class InlineGreyTextTagger : ITagger<IntraTextAdornmentTag>
{
protected readonly IWpfTextView view;
protected SnapshotSpan currentSpan;
private Brush greyBrush;
private StackPanel stackPanel;
public event EventHandler<SnapshotSpanEventArgs> TagsChanged;

public InlineGreyTextTagger(IWpfTextView view)
{
this.view = view;
this.greyBrush = new SolidColorBrush(Colors.Gray);
this.stackPanel = new StackPanel();
}
public InlineGreyTextTagger(IWpfTextView view)
{
this.view = view;
this.greyBrush = new SolidColorBrush(Colors.Gray);
this.stackPanel = new StackPanel();
}

/// <param name="span">The span of text that this adornment will elide.</param>
/// <returns>Adornment corresponding to given data. May be null.</returns>
public void UpdateAdornment(UIElement text)
{
ClearAdornment();
stackPanel.Children.Add(text);
stackPanel.UpdateLayout();
}

/// <param name="span">The span of text that this adornment will elide.</param>
/// <returns>Adornment corresponding to given data. May be null.</returns>
public void UpdateAdornment(UIElement text)
{
ClearAdornment();
stackPanel.Children.Add(text);
stackPanel.UpdateLayout();
}
public void ClearAdornment()
{
stackPanel.Children.Clear();
stackPanel = new StackPanel();
}

public void ClearAdornment()
{
stackPanel.Children.Clear();
stackPanel = new StackPanel();
}
public void FormatText(TextRunProperties props)
{
if (props == null) { return; }

public void FormatText(TextRunProperties props)
foreach (TextBlock block in stackPanel.Children)
{
if (props == null)
{
return;
}

foreach (TextBlock block in stackPanel.Children)
{
block.FontFamily = props.Typeface.FontFamily;
block.FontSize = props.FontRenderingEmSize;
}
block.FontFamily = props.Typeface.FontFamily;
block.FontSize = props.FontRenderingEmSize;
}
}

public void MarkDirty()
{
var changeStart = view.TextViewLines.FirstVisibleLine.Start;
var changeEnd = view.TextViewLines.LastVisibleLine.Start;

var startLine = view.TextSnapshot.GetLineFromPosition(changeStart);
var endLine = view.TextSnapshot.GetLineFromPosition(changeEnd);
public void MarkDirty()
{
var changeStart = view.TextViewLines.FirstVisibleLine.Start;
var changeEnd = view.TextViewLines.LastVisibleLine.Start;

var span = new SnapshotSpan(startLine.Start, endLine.EndIncludingLineBreak).
TranslateTo(targetSnapshot: view.TextBuffer.CurrentSnapshot, SpanTrackingMode.EdgePositive);
var startLine = view.TextSnapshot.GetLineFromPosition(changeStart);
var endLine = view.TextSnapshot.GetLineFromPosition(changeEnd);

TagsChanged(this, new SnapshotSpanEventArgs(new SnapshotSpan(span.Start, span.End)));
}
var span = new SnapshotSpan(startLine.Start, endLine.EndIncludingLineBreak)
.TranslateTo(targetSnapshot: view.TextBuffer.CurrentSnapshot,
SpanTrackingMode.EdgePositive);

// Produces tags on the snapshot that the tag consumer asked for.
public virtual IEnumerable<ITagSpan<IntraTextAdornmentTag>> GetTags(NormalizedSnapshotSpanCollection spans)
{
if (stackPanel.Children.Count == 0)
{
yield break;
}

ITextSnapshot requestedSnapshot = spans[0].Snapshot;
double width = view.FormattedLineSource.ColumnWidth * ((stackPanel.Children[0] as TextBlock).Inlines.First() as Run).Text.Length;
double height = view.LineHeight;

stackPanel.Measure(new Size(width, height));
stackPanel.MaxHeight = height;
stackPanel.MinHeight = height;
stackPanel.MinWidth = width;
stackPanel.MaxWidth = width;
var caretLine = view.Caret.ContainingTextViewLine;
SnapshotPoint point = view.Caret.Position.BufferPosition.TranslateTo(requestedSnapshot, PointTrackingMode.Positive);
var line = requestedSnapshot.GetLineFromPosition(point);
var span = new SnapshotSpan(point, point);

IntraTextAdornmentTag tag = new IntraTextAdornmentTag(stackPanel, null, PositionAffinity.Successor);
yield return new TagSpan<IntraTextAdornmentTag>(span, tag);
}
TagsChanged(this, new SnapshotSpanEventArgs(new SnapshotSpan(span.Start, span.End)));
}

// Produces tags on the snapshot that the tag consumer asked for.
public virtual IEnumerable<ITagSpan<IntraTextAdornmentTag>>
GetTags(NormalizedSnapshotSpanCollection spans)
{
if (stackPanel.Children.Count == 0) { yield break; }

ITextSnapshot requestedSnapshot = spans[0].Snapshot;
double width = view.FormattedLineSource.ColumnWidth *
((stackPanel.Children[0] as TextBlock).Inlines.First() as Run).Text.Length;
double height = view.LineHeight;

stackPanel.Measure(new Size(width, height));
stackPanel.MaxHeight = height;
stackPanel.MinHeight = height;
stackPanel.MinWidth = width;
stackPanel.MaxWidth = width;
var caretLine = view.Caret.ContainingTextViewLine;
SnapshotPoint point = view.Caret.Position.BufferPosition.TranslateTo(
requestedSnapshot, PointTrackingMode.Positive);
var line = requestedSnapshot.GetLineFromPosition(point);
var span = new SnapshotSpan(point, point);

IntraTextAdornmentTag tag =
new IntraTextAdornmentTag(stackPanel, null, PositionAffinity.Successor);
yield return new TagSpan<IntraTextAdornmentTag>(span, tag);
}
}

[Export(contractType: typeof(IViewTaggerProvider))]
[TagType(typeof(IntraTextAdornmentTag))]
[ContentType("text")]
internal class InlineTaggerProvider : IViewTaggerProvider
[Export(contractType: typeof(IViewTaggerProvider))]
[TagType(typeof(IntraTextAdornmentTag))]
[ContentType("text")]
internal class InlineTaggerProvider : IViewTaggerProvider
{
// create a single tagger for each buffer.
// the InlineGreyTextTagger displays grey text inserted between user text in the editor.
public ITagger<T> CreateTagger<T>(ITextView textView, ITextBuffer buffer)
where T : ITag
{
//create a single tagger for each buffer.
//the InlineGreyTextTagger displays grey text inserted between user text in the editor.
public ITagger<T> CreateTagger<T>(ITextView textView, ITextBuffer buffer) where T : ITag
Func<ITagger<T>> sc = delegate()
{
Func<ITagger<T>> sc = delegate () { return new InlineGreyTextTagger((IWpfTextView)textView) as ITagger<T>; };
return buffer.Properties.GetOrCreateSingletonProperty(typeof(InlineGreyTextTagger), sc);
}
return new InlineGreyTextTagger((IWpfTextView)textView) as ITagger<T>;
};
return buffer.Properties.GetOrCreateSingletonProperty(typeof(InlineGreyTextTagger), sc);
}
}

}
2 changes: 1 addition & 1 deletion CodeiumVS/SuggestionUI/Mapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ internal class KnownLanguages
new LangInfo("XML", "xml", Packets.Language.LANGUAGE_XML),
new LangInfo("XSL", "xsl", Packets.Language.LANGUAGE_XSL),
new LangInfo("YAML", "yaml", Packets.Language.LANGUAGE_YAML),
// clang-format on
// clang-format on
];
}
internal class LanguageEqualityComparer : IEqualityComparer<LangInfo>
Expand Down
133 changes: 65 additions & 68 deletions CodeiumVS/SuggestionUI/StringCompare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,90 +6,87 @@

namespace CodeiumVS
{
public static class StringCompare
{
public static class StringCompare
{

//returns the number of times letter c appears in s
public static int GetOccurenceOfLetter(String s, char c)
{
int n = 0;
for (int i = 0; (i = s.IndexOf(c, i)) >= 0; i++, n++) { }
return n;
}
// returns the number of times letter c appears in s
public static int GetOccurenceOfLetter(String s, char c)
{
int n = 0;
for (int i = 0; (i = s.IndexOf(c, i)) >= 0; i++, n++) {}
return n;
}

//skips whitespace
public static int nextNonWhitespace(String s, int index)
{
for (; index < s.Length && Char.IsWhiteSpace(s[index]); index++) ; ;
return index;
}
// skips whitespace
public static int nextNonWhitespace(String s, int index)
{
for (; index < s.Length && Char.IsWhiteSpace(s[index]); index++)
;
;
return index;
}

public static bool IsNameChar(char c)
{
return Char.IsLetterOrDigit(c) || c == '_';
}
public static bool IsNameChar(char c) { return Char.IsLetterOrDigit(c) || c == '_'; }

//Compares the two strings to see if a is a prefix of b ignoring whitespace
public static Tuple<int, int> CompareStrings(String a, String b)
// Compares the two strings to see if a is a prefix of b ignoring whitespace
public static Tuple<int, int> CompareStrings(String a, String b)
{
int a_index = 0, b_index = 0;
while (a_index < a.Length && b_index < b.Length)
{
int a_index = 0, b_index = 0;
while (a_index < a.Length && b_index < b.Length)
char aChar = a[a_index];
char bChar = b[b_index];
if (aChar == bChar)
{
char aChar = a[a_index];
char bChar = b[b_index];
if (aChar == bChar)
{
a_index++;
b_index++;
}
else
a_index++;
b_index++;
}
else
{
if (Char.IsWhiteSpace(bChar))
{
if (Char.IsWhiteSpace(bChar))
{
b_index = nextNonWhitespace(b, b_index);
b_index = nextNonWhitespace(b, b_index);

continue;
}

if (Char.IsWhiteSpace(aChar) && b_index >= 1 && (!IsNameChar(b[b_index]) || !IsNameChar(b[b_index - 1])))
{
a_index = nextNonWhitespace(a, a_index);
continue;
}

continue;
}
if (Char.IsWhiteSpace(aChar) && b_index >= 1 &&
(!IsNameChar(b[b_index]) || !IsNameChar(b[b_index - 1])))
{
a_index = nextNonWhitespace(a, a_index);

break;
continue;
}
}

return new Tuple<int, int>(a_index, b_index);
break;
}
}

//Check if the text in the editor is a substring of the the suggestion text
//If it matches return the line number of the suggestion text that matches the current line in the editor
//else return -1
public static int CheckSuggestion(String suggestion, String line, bool isTextInsertion = false, int insertionPoint = -1)
{
if (line.Length == 0)
{
return 0;
}
return new Tuple<int, int>(a_index, b_index);
}

int index = suggestion.IndexOf(line);
int endPos = index + line.Length;
int firstLineBreak = suggestion.IndexOf('\n');
// Check if the text in the editor is a substring of the the suggestion text
// If it matches return the line number of the suggestion text that matches the current line in
// the editor else return -1
public static int CheckSuggestion(String suggestion, String line, bool isTextInsertion = false,
int insertionPoint = -1)
{
if (line.Length == 0) { return 0; }

if (index > -1 && (firstLineBreak == -1 || endPos < firstLineBreak))
{
return index == 0 ? line.Length : -1;
}
else
{
Tuple<int, int> res = CompareStrings(line, suggestion);
int endPoint = isTextInsertion ? line.Length - insertionPoint : line.Length;
return res.Item1 >= endPoint ? res.Item2 : -1;
}
}
int index = suggestion.IndexOf(line);
int endPos = index + line.Length;
int firstLineBreak = suggestion.IndexOf('\n');

if (index > -1 && (firstLineBreak == -1 || endPos < firstLineBreak))
{
return index == 0 ? line.Length : -1;
}
else
{
Tuple<int, int> res = CompareStrings(line, suggestion);
int endPoint = isTextInsertion ? line.Length - insertionPoint : line.Length;
return res.Item1 >= endPoint ? res.Item2 : -1;
}
}
}
}
Loading

0 comments on commit e90a001

Please sign in to comment.