Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat: fix code file type match display (#193)

gbirman33d15884972c
diff --git a/js/app/packages/block-code/util/languageSupport.ts b/js/app/packages/block-code/util/languageSupport.ts
index 89a7553990..edad5927b3 100644
--- a/js/app/packages/block-code/util/languageSupport.ts
+++ b/js/app/packages/block-code/util/languageSupport.ts
@@ -1,4 +1,5 @@
import type { Extension } from '@codemirror/state';
+import { FileTypeMap } from '@service-storage/fileTypeMap';
type LanguageLoader = () => Promise<Extension>;
@@ -110,12 +111,24 @@ const extensionToLanguage: Record<string, string> = {
csv: 'plaintext',
};
+// Build supported extensions from FileTypeMap where app === 'code'
+const codeFileExtensions = Object.values(FileTypeMap)
+ .filter((fileType) => fileType.app === 'code')
+ .map((fileType) => fileType.extension);
+
+export type CodeFileExtension = (typeof codeFileExtensions)[number];
+
+// Combine with our explicitly mapped extensions
+const allSupportedExtensions = [
+ ...new Set([...Object.keys(extensionToLanguage), ...codeFileExtensions]),
+];
+
// Supported languages (source of truth for block-code)
export const supportedLanguages = Object.keys(languageLoaders);
export const supportedLanguageSet = new Set(supportedLanguages);
-// Supported file extensions
-export const supportedExtensions = Object.keys(extensionToLanguage);
+// Supported file extensions (derived from FileTypeMap)
+export const supportedExtensions = allSupportedExtensions;
export const supportedExtensionSet = new Set(supportedExtensions);
// Language aliases to file extensions (for create.ts compatibility)
@@ -156,15 +169,23 @@ export const langIdSet = new Set([
// Export supported languages as langId for compatibility
export const langId = supportedLanguages;
-// File extensions for type compatibility
-export const filesExtensions = supportedExtensions;
-export const fileExtensionSet = supportedExtensionSet;
-
export function detectLanguageFromExtension(
fileExtension: string
): string | null {
const normalizedExt = fileExtension.toLowerCase().replace(/^\./, '');
- return extensionToLanguage[normalizedExt] || null;
+
+ // Check if we have an explicit language mapping
+ if (extensionToLanguage[normalizedExt]) {
+ return extensionToLanguage[normalizedExt];
+ }
+
+ // Return plaintext as fallback for code files without explicit language mapping
+ const matchesCodeFileType = codeFileExtensions.includes(normalizedExt as any);
+ if (matchesCodeFileType) {
+ return 'plaintext';
+ }
+
+ return null;
}
export async function loadLanguageExtension(
diff --git a/js/app/packages/core/component/EntityIcon.tsx b/js/app/packages/core/component/EntityIcon.tsx
index 9409f815ff..f6e27ecda6 100644
--- a/js/app/packages/core/component/EntityIcon.tsx
+++ b/js/app/packages/core/component/EntityIcon.tsx
@@ -1,3 +1,4 @@
+import { supportedExtensionSet } from '@block-code/util/languageSupport';
import type { BlockName } from '@core/block';
import { fileTypeToBlockName } from '@core/constant/allBlocks';
import { USE_PIXEL_BLOCK_ICONS } from '@core/constant/featureFlags';
@@ -41,7 +42,7 @@ import PixelUser from '@macro-icons/pixel/user.svg';
import PixelUsers from '@macro-icons/pixel/users.svg';
import PixelVideo from '@macro-icons/pixel/video.svg';
import PixelWord from '@macro-icons/pixel/write.svg';
-import { FileType } from '@service-storage/generated/schemas/fileType';
+import type { FileType } from '@service-storage/generated/schemas/fileType';
import type { Component, JSX } from 'solid-js';
import { Dynamic } from 'solid-js/web';
@@ -196,8 +197,8 @@ export const ENTITY_ICON_CONFIGS: Record<EntityWithValidIcon, IconConfig> = {
},
};
-function isFileType(entity: string): entity is FileType {
- return entity in FileType;
+function isFileType(entity: string): boolean {
+ return supportedExtensionSet.has(entity);
}
function validateEntity(entity: string): EntityWithValidIcon {
diff --git a/js/app/packages/core/util/create.ts b/js/app/packages/core/util/create.ts
index e71351e111..5270ce9a03 100644
--- a/js/app/packages/core/util/create.ts
+++ b/js/app/packages/core/util/create.ts
@@ -1,4 +1,4 @@
-import type { filesExtensions } from '@block-code/util/languageSupport';
+import type { CodeFileExtension } from '@block-code/util/languageSupport';
import { MARKDOWN_LORO_SCHEMA } from '@block-md/definition';
import { rawStateToLoroSnapshot } from '@core/collab/utils';
import { createMarkdownStateFromContent } from '@core/component/LexicalMarkdown/collaboration/utils';
@@ -85,7 +85,7 @@ export async function createCodeFileFromText({
}: {
code: string;
title?: string;
- extension: (typeof filesExtensions)[number];
+ extension: CodeFileExtension;
}) {
const encoder = new TextEncoder();
const buffer = encoder.encode(code);