-
Notifications
You must be signed in to change notification settings - Fork 93
fix: Fixed an issue with DAP code fragment creation for languages with dialects (fixes #1118 and #1456) #1466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e7f1d2f
b946987
3aad137
e5685df
05a6364
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2026 Red Hat, Inc. | ||
| * Distributed under license by Red Hat, Inc. All rights reserved. | ||
| * This program is made available under the terms of the | ||
| * Eclipse Public License v2.0 which accompanies this distribution, | ||
| * and is available at http://www.eclipse.org/legal/epl-v20.html | ||
| * | ||
| * Contributors: | ||
| * Red Hat, Inc. - initial API and implementation | ||
| ******************************************************************************/ | ||
|
|
||
| package com.redhat.devtools.lsp4ij.dap; | ||
|
|
||
| import com.intellij.json.JsonFileType; | ||
| import com.intellij.json.JsonLanguage; | ||
| import com.intellij.json.json5.Json5Language; | ||
| import com.intellij.openapi.fileTypes.MockLanguageFileType; | ||
| import com.intellij.openapi.fileTypes.PlainTextFileType; | ||
| import com.intellij.openapi.fileTypes.PlainTextLanguage; | ||
| import com.intellij.openapi.vfs.VirtualFile; | ||
| import com.intellij.psi.PsiFile; | ||
| import com.intellij.psi.PsiFileFactory; | ||
| import com.intellij.testFramework.LightPlatformTestCase; | ||
| import com.intellij.testFramework.LightVirtualFile; | ||
|
|
||
| public class DAPDebuggerEditorsProviderTest extends LightPlatformTestCase { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added tests to verify the original behavior for simple file types with a single language and the corrected behavior for more complex file types that can have multiple dialects of a language. |
||
|
|
||
| public void testWithSimpleLanguage() { | ||
| PsiFile textFile = createFile("test.txt", "Hello, world."); | ||
| assertEquals(PlainTextFileType.INSTANCE, textFile.getFileType()); | ||
| assertEquals(PlainTextLanguage.INSTANCE, textFile.getLanguage()); | ||
|
|
||
| DAPDebuggerEditorsProvider debuggerEditorsProvider = new DAPDebuggerEditorsProvider(PlainTextFileType.INSTANCE, null); | ||
|
|
||
| PsiFile codeFragment = debuggerEditorsProvider.createExpressionCodeFragment(getProject(), "", textFile, true); | ||
| assertEquals(PlainTextFileType.INSTANCE, codeFragment.getFileType()); | ||
| assertEquals(PlainTextLanguage.INSTANCE, codeFragment.getLanguage()); | ||
| } | ||
|
|
||
| public void testWithDialectLanguage() { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use JSON here because it already has a JSON5 dialect/variant, though it still operates differently than the JavaScript ones because for JSON, there's a 1:1 correspondence between file types ( |
||
| // Create a file with the dialect language | ||
| PsiFile dialectFile = PsiFileFactory.getInstance(getProject()).createFileFromText("test.json", Json5Language.INSTANCE, "{}"); | ||
| VirtualFile dialectVirtualFile = dialectFile.getVirtualFile(); | ||
| // Force the file type to be the base instead of the one inferred from the dialect language used above | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And that one thing is right here. At this point, the file type of |
||
| ((LightVirtualFile) dialectVirtualFile).setFileType(JsonFileType.INSTANCE); | ||
| assertEquals(JsonFileType.INSTANCE, dialectFile.getFileType()); | ||
| assertEquals(Json5Language.INSTANCE, dialectFile.getLanguage()); | ||
|
|
||
| // This should also use the base file type | ||
| DAPDebuggerEditorsProvider debuggerEditorsProvider = new DAPDebuggerEditorsProvider(MockLanguageFileType.INSTANCE, null); | ||
|
|
||
| // If the original issue exists, this will fail with "JSON5 doesn't participate in view provider..." | ||
| PsiFile codeFragment = debuggerEditorsProvider.createExpressionCodeFragment(getProject(), "", dialectFile, true); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| assertEquals(JsonFileType.INSTANCE, codeFragment.getFileType()); | ||
| // It should have degraded to the base language | ||
| assertEquals(JsonLanguage.INSTANCE, codeFragment.getLanguage()); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main logic change for the fix. It basically does what's described in the PR itself.