Skip to content

Commit

Permalink
fix(syntax/#2985): PHP syntax highlights not showing (#2997)
Browse files Browse the repository at this point in the history
__Issue:__ PHP syntax highlights are no longer showing by default

__Defect:__ #2889 upgraded the extensions, but the PHP extension has a new dependency on `embeddedLanguages`, which our current textmate implementation does not handle correctly

__Fix:__ Remove the `embeddedLanguages` for now - add a regression / canary test to ensure we don't break this in the future.

Fixes #2985 
Tracking `embeddedLanguage` support in #2998
  • Loading branch information
bryphe authored Jan 15, 2021
1 parent 06493ff commit a4661f7
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGES_CURRENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
- #2990 - Signature Help: Fix blocking `esc` key press back to normal mode
- #2991 - OSX: Fix shortcut keys double-triggering events
- #2993 - CodeLens: Handle null command id & label icons
- #2997 - Syntax: Fix regression in syntax highlighting for PHP (fixes #2985)
- #2995 - Extensions: Fix bug with 3-param http/https request (fixes #2981)

### Performance
Expand Down
14 changes: 0 additions & 14 deletions extensions/php/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,6 @@
"language": "php",
"scopeName": "source.php",
"path": "./syntaxes/php.tmLanguage.json"
},
{
"language": "php",
"scopeName": "text.html.php",
"path": "./syntaxes/html.tmLanguage.json",
"embeddedLanguages": {
"text.html": "html",
"source.php": "php",
"source.sql": "sql",
"text.xml": "xml",
"source.js": "javascript",
"source.json": "json",
"source.css": "css"
}
}
],
"snippets": [
Expand Down
60 changes: 60 additions & 0 deletions integration_test/SyntaxHighlightPhpTest.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
open Oni_Core;
open Oni_Model;
open Oni_IntegrationTestLib;

let uniqueColorCount: list(ThemeToken.t) => int =
tokens => {
let rec loop = (uniqueCount, maybeLastForeground, tokens) => {
switch (tokens) {
| [] => uniqueCount
| [(hd: ThemeToken.t), ...tail] =>
switch (maybeLastForeground) {
| None => loop(uniqueCount + 1, Some(hd.foregroundColor), tail)
| Some(color) =>
if (Revery.Color.equals(color, hd.foregroundColor)) {
loop(uniqueCount, Some(hd.foregroundColor), tail);
} else {
loop(uniqueCount + 1, Some(hd.foregroundColor), tail);
}
}
};
};

loop(0, None, tokens);
};

// Integration test - verify we get highlights for PHP
// Regression test for #2985
runTest(~name="SyntaxHighlightPhpTest", ({dispatch, wait, _}) => {
wait(~name="Capture initial state", (state: State.t) =>
Selectors.mode(state) |> Vim.Mode.isNormal
);
wait(~name="Wait for syntax server", ~timeout=10.0, (state: State.t) => {
Feature_Syntax.isSyntaxServerRunning(state.syntaxHighlights)
});

let testFile = getAssetPath("test-syntax.php");

// Create a buffer
dispatch(Actions.OpenFileByPath(testFile, None, None));

// Wait for highlights to show up
wait(~name="Verify we get syntax highlights", (state: State.t) => {
state
|> Selectors.getActiveBuffer
|> Option.map(Buffer.getId)
|> Option.map(bufferId => {
let tokens =
Feature_Syntax.getTokens(
~bufferId,
~line=EditorCoreTypes.LineNumber.(zero),
state.syntaxHighlights,
);

let uniqueTokenColors = tokens |> uniqueColorCount;

uniqueTokenColors > 1;
})
|> Option.value(~default=false)
});
});
28 changes: 14 additions & 14 deletions integration_test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
RegressionCommandLineNoCompletionTest RegressionFontFallbackTest
RegressionFileModifiedIndicationTest RegressionNonExistentDirectory
RegressionVspEmptyInitialBufferTest RegressionVspEmptyExistingBufferTest
SCMGitTest SyntaxHighlightTextMateTest SyntaxHighlightTreesitterTest
AddRemoveSplitTest TerminalSetPidTitleTest TerminalConfigurationTest
TypingBatchedTest TypingUnbatchedTest VimSimpleRemapTest
VimlRemapCmdlineTest ClipboardChangeTest VimScriptLocalFunctionTest
ZenModeSingleFileModeTest ZenModeSplitTest)
SCMGitTest SyntaxHighlightPhpTest SyntaxHighlightTextMateTest
SyntaxHighlightTreesitterTest AddRemoveSplitTest TerminalSetPidTitleTest
TerminalConfigurationTest TypingBatchedTest TypingUnbatchedTest
VimSimpleRemapTest VimlRemapCmdlineTest ClipboardChangeTest
VimScriptLocalFunctionTest ZenModeSingleFileModeTest ZenModeSplitTest)
(libraries Oni_CLI Oni_IntegrationTestLib reason-native-crash-utils.asan))

(install
Expand Down Expand Up @@ -54,12 +54,12 @@
SearchShowClearHighlightsTest.exe SyntaxHighlightTextMateTest.exe
SyntaxHighlightTreesitterTest.exe SyntaxServer.exe
SyntaxServerCloseTest.exe SyntaxServerMessageExceptionTest.exe
SyntaxServerParentPidTest.exe SyntaxServerParentPidCorrectTest.exe
SyntaxServerReadExceptionTest.exe TerminalSetPidTitleTest.exe
TerminalConfigurationTest.exe AddRemoveSplitTest.exe TypingBatchedTest.exe
TypingUnbatchedTest.exe VimScriptLocalFunctionTest.exe
VimSimpleRemapTest.exe VimlRemapCmdlineTest.exe
ZenModeSingleFileModeTest.exe ZenModeSplitTest.exe ClipboardChangeTest.exe
large-c-file.c lsan.supp some-test-file.json some-test-file.txt test.crlf
test.lf utf8.txt utf8-test-file.htm Inconsolata-Regular.ttf
PlugScriptLocal.vim))
SyntaxHighlightPhpTest.exe SyntaxServerParentPidTest.exe
SyntaxServerParentPidCorrectTest.exe SyntaxServerReadExceptionTest.exe
TerminalSetPidTitleTest.exe TerminalConfigurationTest.exe
AddRemoveSplitTest.exe TypingBatchedTest.exe TypingUnbatchedTest.exe
VimScriptLocalFunctionTest.exe VimSimpleRemapTest.exe
VimlRemapCmdlineTest.exe ZenModeSingleFileModeTest.exe
ZenModeSplitTest.exe ClipboardChangeTest.exe large-c-file.c lsan.supp
some-test-file.json some-test-file.txt test.crlf test.lf test-syntax.php
utf8.txt utf8-test-file.htm Inconsolata-Regular.ttf PlugScriptLocal.vim))
1 change: 1 addition & 0 deletions integration_test/test-syntax.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php echo "Hello, world!" ?>
2 changes: 1 addition & 1 deletion src/Core/ThemeToken.re
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ let toString =
Printf.sprintf(
"ColorizedToken - index: %d foreground: %s background: %s scope: %s bold: %b italic: %b",
index,
backgroundColor |> Revery.Color.toString,
foregroundColor |> Revery.Color.toString,
backgroundColor |> Revery.Color.toString,
syntaxScope |> SyntaxScope.toString,
bold,
italic,
Expand Down

0 comments on commit a4661f7

Please sign in to comment.