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

fix: codelens links for moonraker-telegram-bot #742

Merged
merged 1 commit into from
Jul 5, 2022
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
48 changes: 29 additions & 19 deletions src/components/widgets/filesystem/setupMonaco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@ import getVueApp from '@/util/get-vue-app'
import themeDark from '@/monaco/theme/editor.dark.theme.json'
import themeLight from '@/monaco/theme/editor.light.theme.json'

const extruderRegExp = /^extruder[0-9]+$/

const getDocsSection = (sectionName: string) => {
if (sectionName.startsWith('stepper_')) {
return 'stepper'
}
type CodeLensSupportedService = 'klipper' | 'moonraker' | 'moonraker-telegram-bot'

const isCodeLensSupportedService = (service: string) : service is CodeLensSupportedService => [
'klipper',
'moonraker',
'moonraker-telegram-bot'
].includes(service)

const getDocsSection = (service: CodeLensSupportedService, sectionName: string) => {
switch (service) {
case 'klipper':
if (sectionName.startsWith('stepper_')) {
return 'stepper'
}

if (extruderRegExp.test(sectionName)) {
return 'extruder'
if (/^extruder[0-9]+$/.test(sectionName)) {
return 'extruder'
}
}

return sectionName
Expand Down Expand Up @@ -66,19 +75,20 @@ async function setupMonaco () {

const app = getVueApp()

monaco.editor.registerCommand('fluidd_open_docs', (_, isMoonrakerConfig, hash) => {
if (isMoonrakerConfig) {
const url = app.$t('app.file_system.url.moonraker_config', { hash }).toString()
window.open(url)
} else {
const url = app.$t('app.file_system.url.klipper_config', { hash }).toString()
window.open(url)
}
monaco.editor.registerCommand('fluidd_open_docs', (_, service: CodeLensSupportedService, hash: string) => {
const serviceKey = service.replace(/-/g, '_')
const url = app.$t(`app.file_system.url.${serviceKey}_config`, { hash }).toString()

window.open(url)
})

monaco.languages.registerCodeLensProvider('klipper-config', {
provideCodeLenses: (model) => {
const isMoonrakerConfig = model.uri.path.toLowerCase().endsWith('/moonraker.conf')
const { service } = app.$store.getters['server/getConfigMapByFilename'](model.uri.path.split('/').pop())

if (!isCodeLensSupportedService(service)) {
return null
}

const linesContent = model.getLinesContent()

Expand All @@ -87,7 +97,7 @@ async function setupMonaco () {
if (section) {
const [sectionName] = section[1].split(' ')

const referenceSection = getDocsSection(sectionName)
const referenceSection = getDocsSection(service, sectionName)

return ranges.concat({
referenceSection,
Expand All @@ -110,7 +120,7 @@ async function setupMonaco () {
command: {
id: 'fluidd_open_docs',
title: app.$t('app.file_system.label.view_section_documentation', { section: section.referenceSection }).toString(),
arguments: [isMoonrakerConfig, section.referenceSection]
arguments: [service, section.referenceSection]
}
})
),
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ app:
url:
klipper_config: 'https://www.klipper3d.org/Config_Reference.html#%{hash}'
moonraker_config: 'https://moonraker.readthedocs.io/en/latest/configuration/#%{hash}'
moonraker_telegram_bot_config: 'https://github.com/nlef/moonraker-telegram-bot/wiki/Sample-config#%{hash}'
gcode:
btn:
load_current_file: Load Current File
Expand Down