Skip to content

Commit 42864ca

Browse files
committed
Refactor Roslyn document retrieval and enhance completion trigger handling for non-workspace files
1 parent 6b1398b commit 42864ca

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/SharpIDE.Application/Features/Analysis/RoslynAnalysis.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,12 @@ public async Task<ImmutableArray<SharpIdeDiagnostic>> GetDocumentAnalyzerDiagnos
469469
private static async Task<Document> GetDocumentForSharpIdeFile(SharpIdeFile fileModel, CancellationToken cancellationToken = default)
470470
{
471471
var project = GetProjectForSharpIdeFile(fileModel);
472-
var document = fileModel.IsCsharpFile ? project.Documents.SingleOrDefault(s => s.FilePath == fileModel.Path)
473-
: await GetRazorSourceGeneratedDocumentInProjectForSharpIdeFile(project, fileModel, cancellationToken);
472+
Document? document = fileModel switch
473+
{
474+
{ IsCsharpFile: true } => project.Documents.SingleOrDefault(s => s.FilePath == fileModel.Path),
475+
{ IsRazorFile: true } => await GetRazorSourceGeneratedDocumentInProjectForSharpIdeFile(project, fileModel, cancellationToken),
476+
_ => throw new InvalidOperationException($"Roslyn document lookup is not supported for file '{fileModel.Path}'.")
477+
};
474478
Guard.Against.Null(document, nameof(document));
475479
return document;
476480
}

src/SharpIDE.Godot/Features/CodeEditor/SharpIdeCodeEdit.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,18 @@ private void OnTextChanged()
271271
{
272272
var __ = SharpIdeOtel.Source.StartActivity($"{nameof(SharpIdeCodeEdit)}.{nameof(OnTextChanged)}");
273273
_currentFile.IsDirty.Value = true;
274-
await _fileChangedService.SharpIdeFileChanged(_currentFile, text, FileChangeType.IdeUnsavedChange);
275-
if (pendingCompletionTrigger is not null)
276-
{
277-
_completionTrigger = pendingCompletionTrigger;
278-
var linePosition = new LinePosition(cursorPosition.line, cursorPosition.col);
279-
var shouldTriggerCompletion = await _roslynAnalysis.ShouldTriggerCompletionAsync(_currentFile, text, linePosition, _completionTrigger!.Value);
274+
await _fileChangedService.SharpIdeFileChanged(_currentFile, text, FileChangeType.IdeUnsavedChange);
275+
if (pendingCompletionTrigger is not null)
276+
{
277+
if (_currentFile.IsRoslynWorkspaceFile is false)
278+
{
279+
HighlightLog($"Skipping Roslyn completion trigger for non-workspace file '{_currentFile.Path}'");
280+
return;
281+
}
282+
283+
_completionTrigger = pendingCompletionTrigger;
284+
var linePosition = new LinePosition(cursorPosition.line, cursorPosition.col);
285+
var shouldTriggerCompletion = await _roslynAnalysis.ShouldTriggerCompletionAsync(_currentFile, text, linePosition, _completionTrigger!.Value);
280286
GD.Print($"Code completion trigger typed: '{_completionTrigger.Value.Character}' at {linePosition.Line}:{linePosition.Character} should trigger: {shouldTriggerCompletion}");
281287
if (shouldTriggerCompletion)
282288
{

0 commit comments

Comments
 (0)