Skip to content
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

Support unknown languages #1648

Merged
merged 1 commit into from
Mar 13, 2024
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
4 changes: 2 additions & 2 deletions report-viewer/src/components/fileDisplaying/CodePanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import Interactable from '../InteractableComponent.vue'
import type { Match } from '@/model/Match'
import type { SubmissionFile } from '@/model/File'
import { highlight } from '@/utils/CodeHighlighter'
import type { ParserLanguage } from '@/model/Language'
import type { Language } from '@/model/Language'
import { getMatchColor } from '@/utils/ColorUtils'
import ToolTipComponent from '../ToolTipComponent.vue'

Expand All @@ -94,7 +94,7 @@ const props = defineProps({
* Language of the file.
*/
highlightLanguage: {
type: String as PropType<ParserLanguage>,
type: String as PropType<Language>,
required: true
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import type { MatchInSingleFile } from '@/model/MatchInSingleFile'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { faCompressAlt } from '@fortawesome/free-solid-svg-icons'
import { library } from '@fortawesome/fontawesome-svg-core'
import type { ParserLanguage } from '@/model/Language'
import type { Language } from '@/model/Language'

library.add(faCompressAlt)

Expand Down Expand Up @@ -78,7 +78,7 @@ const props = defineProps({
* Language of the files.
*/
highlightLanguage: {
type: String as PropType<ParserLanguage>,
type: String as PropType<Language>,
required: true
}
})
Expand Down
4 changes: 2 additions & 2 deletions report-viewer/src/model/CliOptions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { ParserLanguage } from './Language'
import type { Language } from './Language'
import type { MetricType } from './MetricType'

export interface CliOptions {
language: ParserLanguage
language: Language
minTokenMatch: number
submissionDirectories: string[]
oldDirectories: string[]
Expand Down
9 changes: 6 additions & 3 deletions report-viewer/src/model/Language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,22 @@ enum ParserLanguage {
TYPESCRIPT = 'Typescript Parser'
}

type Language = ParserLanguage | 'unknown language'

/**
* Gets the LanguageParser enum value for the given language
* @param language String representation of language the files were parsed with
* @returns The LanguageParser enum value
*/
function getLanguageParser(language: string): ParserLanguage {
function getLanguageParser(language: string): Language {
for (const key in ParserLanguage) {
if (ParserLanguage[key as keyof typeof ParserLanguage] === language) {
return ParserLanguage[key as keyof typeof ParserLanguage]
}
}

throw new Error(`Language ${language} not found`)
console.warn(`Unknown language: ${language}\nCode highlighting might not work correctly.`)
return 'unknown language'
}

export { ParserLanguage, getLanguageParser }
export { ParserLanguage, type Language, getLanguageParser }
6 changes: 3 additions & 3 deletions report-viewer/src/model/Overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import type { Distribution } from './Distribution'
import type { Cluster } from '@/model/Cluster'
import type { ComparisonListElement } from './ComparisonListElement'
import type { MetricType } from './MetricType'
import type { ParserLanguage } from './Language'
import type { Language } from './Language'

/**
* Model of the Overview file generated by JPlag
*/
export class Overview {
private readonly _submissionFolderPath: Array<string>
private readonly _baseCodeFolderPath: string
private readonly _language: ParserLanguage
private readonly _language: Language
private readonly _fileExtensions: Array<string>
private readonly _matchSensitivity: number
private readonly _dateOfExecution: string
Expand All @@ -23,7 +23,7 @@ export class Overview {
constructor(
submissionFolderPath: Array<string>,
baseCodeFolderPath: string,
language: ParserLanguage,
language: Language,
fileExtensions: Array<string>,
matchSensitivity: number,
dateOfExecution: string,
Expand Down
6 changes: 3 additions & 3 deletions report-viewer/src/utils/CodeHighlighter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ParserLanguage } from '@/model/Language'
import { type Language, ParserLanguage } from '@/model/Language'
import hljs from 'highlight.js'
import scheme from 'highlight.js/lib/languages/scheme'
import llvm from 'highlight.js/lib/languages/llvm'
Expand All @@ -13,7 +13,7 @@ import typescript from 'highlight.js/lib/languages/typescript'
* @param lang Language to highlight the code with
* @returns
*/
export function highlight(code: string, lang: ParserLanguage) {
export function highlight(code: string, lang: Language) {
const highlightedCode = hljs.highlight(code, { language: getHighlightLanguage(lang) }).value
const openTags: string[] = []
const formattedCode = highlightedCode
Expand All @@ -34,7 +34,7 @@ export function highlight(code: string, lang: ParserLanguage) {
return formattedCode
}

function getHighlightLanguage(lang: ParserLanguage) {
function getHighlightLanguage(lang: Language) {
switch (lang) {
case ParserLanguage.PYTHON:
return 'python'
Expand Down
4 changes: 2 additions & 2 deletions report-viewer/src/viewWrapper/ComparisonViewWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type { Comparison } from '@/model/Comparison'
import { ComparisonFactory } from '@/model/factories/ComparisonFactory'
import LoadingCircle from '@/components/LoadingCircle.vue'
import { redirectOnError } from '@/router'
import type { ParserLanguage } from '@/model/Language'
import type { Language } from '@/model/Language'
import RepositoryReference from '@/components/RepositoryReference.vue'

const props = defineProps({
Expand All @@ -29,7 +29,7 @@ const props = defineProps({
})

const comparison: Ref<Comparison | null> = ref(null)
const language: Ref<ParserLanguage | null> = ref(null)
const language: Ref<Language | null> = ref(null)

// This eslint rule is disabled to allow the use of await in the setup function. Disabling this rule is safe, because the props are gathered from the url, so changing them would reload the pafe anyway.
// eslint-disable-next-line vue/no-setup-props-reactivity-loss
Expand Down
4 changes: 2 additions & 2 deletions report-viewer/src/views/ComparisonView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ import MatchList from '@/components/fileDisplaying/MatchList.vue'
import FilesContainer from '@/components/fileDisplaying/FilesContainer.vue'
import { store } from '@/stores/store'
import Container from '@/components/ContainerComponent.vue'
import { ParserLanguage } from '@/model/Language'
import type { Language } from '@/model/Language'
import hljsLightMode from 'highlight.js/styles/vs.css?raw'
import hljsDarkMode from 'highlight.js/styles/vs2015.css?raw'
import { MetricType } from '@/model/MetricType'
Expand All @@ -129,7 +129,7 @@ const props = defineProps({
required: true
},
language: {
type: Object as PropType<ParserLanguage>,
type: Object as PropType<Language>,
required: true
}
})
Expand Down