-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: quick navigate to configuration file from activity
- Loading branch information
1 parent
827d6d0
commit 75601aa
Showing
9 changed files
with
240 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"terminal-keeper": patch | ||
--- | ||
|
||
fix: quick navigate to configuration file from activity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const esbuild = require('esbuild'); | ||
|
||
const production = process.argv.includes('--production'); | ||
const watch = process.argv.includes('--watch'); | ||
|
||
async function main() { | ||
const ctx = await esbuild.context({ | ||
entryPoints: ['src/extension.ts'], | ||
bundle: true, | ||
format: 'cjs', | ||
minify: production, | ||
sourcemap: !production, | ||
sourcesContent: false, | ||
platform: 'node', | ||
outfile: 'dist/extension.js', | ||
external: ['vscode'], | ||
logLevel: 'silent', | ||
mainFields: ['module', 'main'], | ||
plugins: [ | ||
/* add to the end of plugins array */ | ||
esbuildProblemMatcherPlugin | ||
] | ||
}); | ||
if (watch) { | ||
await ctx.watch(); | ||
} else { | ||
await ctx.rebuild(); | ||
await ctx.dispose(); | ||
} | ||
} | ||
|
||
/** | ||
* @type {import('esbuild').Plugin} | ||
*/ | ||
const esbuildProblemMatcherPlugin = { | ||
name: 'esbuild-problem-matcher', | ||
setup(build) { | ||
build.onStart(() => { | ||
console.log('Build started...'); | ||
}); | ||
build.onEnd((result) => { | ||
result.errors.forEach(({ text, location }) => { | ||
console.error(`✘ [ERROR] ${text}`); | ||
console.error(` ${location.file}:${location.line}:${location.column}:`); | ||
}); | ||
console.info('Build finished!'); | ||
}); | ||
} | ||
}; | ||
|
||
main().catch((e) => { | ||
console.error(e); | ||
process.exit(1); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import path from 'path'; | ||
import { Selection, TextDocument, Uri, window, workspace } from 'vscode'; | ||
import { Configuration } from '../configuration/configuration'; | ||
import { TKTreeItem } from '../explorer/tree-provider'; | ||
import { constants } from '../utils/constants'; | ||
import { showErrorMessageWithDetail, showGenerateConfiguration } from '../utils/utils'; | ||
|
||
const getFileUriBySource = (source: string | undefined): Uri => { | ||
if (source === 'settings.json') { | ||
return Uri.file(path.join(Configuration.vscodeDirPath, source)); | ||
} | ||
return Uri.file(Configuration.sessionFilePath); | ||
}; | ||
|
||
const getKeywordRegex = (treeItem: TKTreeItem): RegExp => { | ||
const { source, keyword } = treeItem; | ||
let keywordFull = keyword || ''; | ||
if (source === 'settings.json') { | ||
keywordFull = `terminal-keeper.${keyword}`; | ||
} | ||
return new RegExp(keywordFull, 'gm'); | ||
}; | ||
|
||
export const navigateAsync = async (treeItem: TKTreeItem): Promise<void> => { | ||
try { | ||
// Write configuration file | ||
const isDefinedSessionFile = await Configuration.isDefinedSessionFile(); | ||
if (!isDefinedSessionFile) { | ||
await showGenerateConfiguration(); | ||
return; | ||
} | ||
|
||
// Get source include keyword | ||
const { source } = treeItem; | ||
const sessionFileUri = getFileUriBySource(source); | ||
const document: TextDocument = await workspace.openTextDocument(sessionFileUri); | ||
const content = document.getText(); | ||
|
||
// Navigate to the session configuration | ||
const regex = getKeywordRegex(treeItem); | ||
const matches = [...content.matchAll(regex)]; | ||
let selections: Selection[] = []; | ||
matches.forEach((match) => { | ||
if (match.index) { | ||
const startPosition = document.positionAt(match.index); | ||
const endPosition = document.positionAt(match.index + match[0].length); | ||
selections.push(new Selection(startPosition, endPosition)); | ||
} | ||
}); | ||
await window.showTextDocument(document, { selection: selections?.[0] }); | ||
} catch (error) { | ||
showErrorMessageWithDetail(constants.openConfigurationFailed, error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.