Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/lib/editorFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1285,8 +1285,9 @@ export default class EditorFile {
/**
* Sets syntax highlighting of the file.
* @param {string} [mode]
* @param {{ recommend?: boolean }} [options]
*/
setMode(mode) {
setMode(mode, options = {}) {
if (this.type !== "editor") return;
const event = createFileEvent(this);
this.#emit("changemode", event);
Expand All @@ -1309,7 +1310,9 @@ export default class EditorFile {
// Store mode info for later use when creating editor view
this.currentMode = mode;
this.currentLanguageExtension = modeInfo?.getExtension() || null;
maybeRecommendLanguageModeExtension(this, modeInfo);
if (options.recommend !== false) {
maybeRecommendLanguageModeExtension(this, modeInfo);
}

// sets file icon
this.#tab.lead(
Expand Down
7 changes: 7 additions & 0 deletions src/lib/editorManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1746,6 +1746,7 @@ async function EditorManager($header, $body) {
editor,
readOnlyCompartment,
getFile,
reapplyActiveFile,
switchFile,
moveFileByPinnedState,
normalizePinnedTabOrder,
Expand Down Expand Up @@ -2944,6 +2945,12 @@ async function EditorManager($header, $body) {
toggleProblemButton();
}

function reapplyActiveFile() {
const file = manager.activeFile;
if (!file || file.type !== "editor" || !file.loaded || file.loading) return;
applyFileToEditor(file, { forceRecreate: true });
}

/**
* Initializes the file tab container.
*/
Expand Down
16 changes: 11 additions & 5 deletions src/lib/languageModeRecommendations.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getModeForPath } from "cm/modelist";
import notificationManager from "lib/notificationManager";
import Path from "utils/Path";
import Url from "utils/Url";
Expand Down Expand Up @@ -98,9 +99,9 @@ class LanguageModeRecommendations {
}

this.pendingKeywords.add(keyword);
void this.showRecommendation(keyword)
.then(() => {
this.notifiedKeywords.add(keyword);
void this.showRecommendation(keyword, filename)
.then((shown) => {
if (shown) this.notifiedKeywords.add(keyword);
})
.catch((error) => {
console.warn("Failed to show extension recommendation.", error);
Expand All @@ -110,8 +111,12 @@ class LanguageModeRecommendations {
});
}

async showRecommendation(keyword) {
async showRecommendation(keyword, filename) {
const hasPlugins = await this.getPluginAvailability(keyword);
// If a plugin registered the mode while the lookup was pending, suppress
// this stale recommendation and leave the keyword eligible for future checks.
if (!hasPlainTextFallback(getModeForPath(filename), filename)) return false;

const displayExt = `.${keyword}`;

if (hasPlugins) {
Expand All @@ -135,7 +140,7 @@ class LanguageModeRecommendations {
},
],
});
return;
return true;
}

const issueUrl = getIssueUrl(keyword);
Expand All @@ -159,6 +164,7 @@ class LanguageModeRecommendations {
},
],
});
return true;
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ async function onDeviceReady() {

// Re-emit events for active file after plugins are loaded
const { activeFile } = editorManager;
for (const file of editorManager.files) {
if (file?.type === "editor") {
file.setMode(undefined, { recommend: false });
}
}
Comment thread
greptile-apps[bot] marked this conversation as resolved.
editorManager.reapplyActiveFile();
if (activeFile?.uri) {
// Re-emit file-loaded event
editorManager.emit("file-loaded", activeFile);
Expand Down