Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
define an enum for different language supported
Browse files Browse the repository at this point in the history
Signed-off-by: Augustin Husson <[email protected]>
  • Loading branch information
Nexucis committed May 20, 2021
1 parent 963c774 commit 5804c31
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
13 changes: 10 additions & 3 deletions src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,23 @@
import { basicSetup } from '@codemirror/basic-setup';
import { EditorState } from '@codemirror/state';
import { EditorView } from '@codemirror/view';
import { PromQLExtension } from '../lang-promql';
import { LanguageType, PromQLExtension } from '../lang-promql';
import { customTheme, promQLHighlightMaterialTheme } from './theme';

const promqlExtension = new PromQLExtension();
let editor: EditorView;

function getFullLanguage(): boolean {
function getFullLanguage(): LanguageType {
const completionSelect = document.getElementById('fullLanguage') as HTMLSelectElement;
const completionValue = completionSelect.options[completionSelect.selectedIndex].value;
return completionValue === 'promql';
switch (completionValue) {
case 'promql':
return LanguageType.PromQL;
case 'metricName':
return LanguageType.MetricName;
default:
return LanguageType.PromQL;
}
}

function setCompletion() {
Expand Down
2 changes: 1 addition & 1 deletion src/lang-promql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
export { PrometheusClient } from './client';
export { CompleteConfiguration, CompleteStrategy } from './complete';
export { LintStrategy } from './lint';
export { PromQLExtension } from './promql';
export { PromQLExtension, LanguageType } from './promql';
12 changes: 8 additions & 4 deletions src/lang-promql/promql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ import { LintStrategy, newLintStrategy, promQLLinter } from './lint';
import { CompletionContext } from '@codemirror/autocomplete';
import { LezerLanguage } from '@codemirror/language';

function promQLLanguage(top: string) {
export enum LanguageType {
PromQL = 'PromQL',
MetricName = 'MetricName',
}

function promQLLanguage(top: LanguageType) {
return LezerLanguage.define({
parser: parser.configure({
top: top,
Expand Down Expand Up @@ -105,9 +110,8 @@ export class PromQLExtension {
return this;
}

asExtension(fullPromQLLanguage = true): Extension {
const top = fullPromQLLanguage ? 'PromQL' : 'MetricName';
const language = promQLLanguage(top);
asExtension(languageType = LanguageType.PromQL): Extension {
const language = promQLLanguage(languageType);
let extension: Extension = [language];
if (this.enableCompletion) {
const completion = language.data.of({
Expand Down

0 comments on commit 5804c31

Please sign in to comment.