diff --git a/README.md b/README.md index d730f1c81..0e466f309 100644 --- a/README.md +++ b/README.md @@ -147,8 +147,6 @@ The continued development and maintenance of GitHub1s is made possible by these ### Chrome Extensions - [Repositree](https://chrome.google.com/webstore/detail/repositree/lafjldoccjnjlcmdhmniholdpjkbgajo) ([chouglesaud/repositree](https://github.com/chouglesaud/repositree)) -- [Open in VS Code](https://chrome.google.com/webstore/detail/open-in-vs-code-github1sc/neloiopjjeflfnecdlajhopdlojlkhll) by [zulhfreelancer](https://github.com/zulhfreelancer) -- [GitHub1s](https://chrome.google.com/webstore/detail/github1s/lodjfmkfbfkpdhnhkcdcoonghhghbkhe) ([fhefh2015/GitHub1s_chrome_extension](https://github.com/fhefh2015/GitHub1s_chrome_extension)) - [github-code-viewer](https://chrome.google.com/webstore/detail/github-code-viewer/ecddapgifccgblebfibdgkagfbdagjfn) ([febaoshan/edge-extensions-github-code-viewer](https://github.com/febaoshan/edge-extensions-github-code-viewer)) - Github1s Extension ([Darkempire78/GitHub1s-Extension](https://github.com/Darkempire78/GitHub1s-Extension)) - [Github Web IDE](https://chrome.google.com/webstore/detail/adjiklnjodbiaioggfpbpkhbfcnhgkfe) ([zvizvi/Github-Web-IDE](https://github.com/zvizvi/Github-Web-IDE)) diff --git a/extensions/github1s/src/adapters/sourcegraph/common.ts b/extensions/github1s/src/adapters/sourcegraph/common.ts index 0fc58fe8e..1e30ee63b 100644 --- a/extensions/github1s/src/adapters/sourcegraph/common.ts +++ b/extensions/github1s/src/adapters/sourcegraph/common.ts @@ -3,7 +3,7 @@ * @author netcon */ -import { ApolloClient, ApolloQueryResult, createHttpLink, InMemoryCache } from '@apollo/client/core'; +import { ApolloClient, createHttpLink, InMemoryCache } from '@apollo/client/core'; import { isNil, trimEnd, trimStart } from '@/helpers/util'; const sourcegraphLink = createHttpLink({ @@ -49,3 +49,7 @@ export const combineGlobsToRegExp = (globs: string[]) => { }; export const escapeRegexp = (text: string): string => text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); + +export const buildRepoPattern = (repo: string) => { + return `^${escapeRegexp(repo)}$`; +}; diff --git a/extensions/github1s/src/adapters/sourcegraph/data-source.ts b/extensions/github1s/src/adapters/sourcegraph/data-source.ts index 3567d1a01..9a2446164 100644 --- a/extensions/github1s/src/adapters/sourcegraph/data-source.ts +++ b/extensions/github1s/src/adapters/sourcegraph/data-source.ts @@ -37,8 +37,6 @@ import { getTextSearchResults } from './search'; type SupportedPlatfrom = 'github' | 'gitlab' | 'bitbucket'; -const escapeRegexp = (text: string): string => text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); - export class SourcegraphDataSource extends DataSource { private static instanceMap: Map = new Map(); private refsPromiseMap: Map> = new Map(); @@ -71,10 +69,6 @@ export class SourcegraphDataSource extends DataSource { return repo; } - buildRepoPattern(repo: string) { - return `^${escapeRegexp(this.buildRepository(repo))}$`; - } - async provideDirectory(repo: string, ref: string, path: string, recursive = false): Promise { const directories = await readDirectory(this.buildRepository(repo), ref, path, recursive); directories.entries.forEach((entry) => { @@ -109,7 +103,7 @@ export class SourcegraphDataSource extends DataSource { // sourcegraph api break binary files and text coding, so we use github api first here if (this.platform === 'github') { try { - return await fetch(`https://raw.githubusercontent.com/${repo}/${ref}/${path}`) + return await fetch(encodeURI(`https://raw.githubusercontent.com/${repo}/${ref}/${path}`)) .then((response) => response.arrayBuffer()) .then((buffer) => ({ content: new Uint8Array(buffer) })); } catch (e) {} @@ -177,8 +171,7 @@ export class SourcegraphDataSource extends DataSource { query: TextSearchQuery, options: TextSearchOptions ): Promise { - const repoPattern = this.buildRepoPattern(repo); - return getTextSearchResults(repoPattern, ref, query, options); + return getTextSearchResults(this.buildRepository(repo), ref, query, options); } async provideCommits(repo: string, options?: CommitsQueryOptions): Promise<(Commit & { files?: ChangedFile[] })[]> { @@ -216,8 +209,7 @@ export class SourcegraphDataSource extends DataSource { character: number, symbol: string ): Promise { - const repoPattern = this.buildRepoPattern(repo); - return getSymbolDefinitions(repoPattern, ref, path, line, character, symbol); + return getSymbolDefinitions(this.buildRepository(repo), ref, path, line, character, symbol); } async provideSymbolReferences( @@ -228,8 +220,7 @@ export class SourcegraphDataSource extends DataSource { character: number, symbol: string ): Promise { - const repoPattern = this.buildRepoPattern(repo); - return getSymbolReferences(repoPattern, ref, path, line, character, symbol); + return getSymbolReferences(this.buildRepository(repo), ref, path, line, character, symbol); } async provideSymbolHover( @@ -240,8 +231,7 @@ export class SourcegraphDataSource extends DataSource { character: number, _symbol: string ): Promise { - const repoPattern = this.buildRepoPattern(repo); - return getSymbolHover(repoPattern, ref, path, line, character); + return getSymbolHover(this.buildRepository(repo), ref, path, line, character); } provideUserAvatarLink(user: string): string { diff --git a/extensions/github1s/src/adapters/sourcegraph/hover.ts b/extensions/github1s/src/adapters/sourcegraph/hover.ts index d33983f48..62a7a3f74 100644 --- a/extensions/github1s/src/adapters/sourcegraph/hover.ts +++ b/extensions/github1s/src/adapters/sourcegraph/hover.ts @@ -37,7 +37,7 @@ const getLSIFHover = async ( const response = await sourcegraphClient.query({ query: LSIFHoverQuery, variables: { - repository: repository, + repository, ref, path: path.slice(1), line, diff --git a/extensions/github1s/src/adapters/sourcegraph/position.ts b/extensions/github1s/src/adapters/sourcegraph/position.ts index 97870b017..6afeb6e9b 100644 --- a/extensions/github1s/src/adapters/sourcegraph/position.ts +++ b/extensions/github1s/src/adapters/sourcegraph/position.ts @@ -4,7 +4,7 @@ */ import { gql } from '@apollo/client/core'; -import { escapeRegexp, sourcegraphClient } from './common'; +import { buildRepoPattern, escapeRegexp, sourcegraphClient } from './common'; import { CodeLocation } from '../types'; const searchPositionsQuery = gql` @@ -48,7 +48,8 @@ const searchPositionsQuery = gql` // get symbol position information base on search, // used by definition, reference and hover export const getSymbolPositions = async (repository: string, ref: string, symbol: string): Promise => { - const repoRefString = ref.toUpperCase() === 'HEAD' ? `repo:${repository}` : `repo:${repository}@${ref}`; + const repoPattern = buildRepoPattern(repository); + const repoRefString = ref.toUpperCase() === 'HEAD' ? `repo:${repoPattern}` : `repo:${repoPattern}@${ref}`; const optionsString = ['context:global', 'type:symbol', 'patternType:regexp', 'case:yes'].join(' '); const patternString = `^${escapeRegexp(symbol)}$`; const query = [repoRefString, optionsString, patternString].join(' '); diff --git a/extensions/github1s/src/adapters/sourcegraph/search.ts b/extensions/github1s/src/adapters/sourcegraph/search.ts index bc78abc14..d658b2705 100644 --- a/extensions/github1s/src/adapters/sourcegraph/search.ts +++ b/extensions/github1s/src/adapters/sourcegraph/search.ts @@ -5,17 +5,18 @@ import { gql } from '@apollo/client/core'; import { TextSearchOptions, TextSearchQuery, TextSearchResults } from '../types'; -import { escapeRegexp, sourcegraphClient, combineGlobsToRegExp } from './common'; +import { escapeRegexp, sourcegraphClient, combineGlobsToRegExp, buildRepoPattern } from './common'; // build text search query for sourcegraph graphql request export const buildTextSearchQueryString = ( - repo: string, + repository: string, ref: string, query: TextSearchQuery, options: TextSearchOptions ): string => { + const repoPattern = buildRepoPattern(repository); const countString = `count:${options.pageSize ? (options.page || 1) * options.pageSize : 100}`; - const repoRefQueryString = ref.toUpperCase() === 'HEAD' ? `repo:${repo}` : `repo:${repo}@${ref}`; + const repoRefString = ref.toUpperCase() === 'HEAD' ? `repo:${repoPattern}` : `repo:${repoPattern}@${ref}`; // the string may looks like `case:yse file:src -file:node_modules` const optionsString = [ query.isCaseSensitive ? `case:yes` : '', @@ -37,7 +38,7 @@ export const buildTextSearchQueryString = ( return `/\b${patternString}\b/`; } - return [repoRefQueryString, optionsString, patternString, countString].filter(Boolean).join(' '); + return [repoRefString, optionsString, patternString, countString].filter(Boolean).join(' '); }; const textSearchQuery = gql` diff --git a/extensions/github1s/src/providers/text-search.ts b/extensions/github1s/src/providers/text-search.ts index aef44f7dd..61b44c9f7 100644 --- a/extensions/github1s/src/providers/text-search.ts +++ b/extensions/github1s/src/providers/text-search.ts @@ -39,7 +39,7 @@ export class GitHub1sTextSearchProvider implements vscode.TextSearchProvider, vs return router.getAuthority().then(async (authority) => { const [repo, ref] = authority.split('+'); const dataSource = await adapterManager.getCurrentAdapter().resolveDataSource(); - const searchOptions = { page: 1, pageSize: 30, includes: options.includes, excludes: options.excludes }; + const searchOptions = { page: 1, pageSize: 100, includes: options.includes, excludes: options.excludes }; const searchResults = await dataSource.provideTextSearchResults(repo, ref, query, searchOptions); const currentScheme = adapterManager.getCurrentScheme(); diff --git a/extensions/github1s/src/router/index.ts b/extensions/github1s/src/router/index.ts index 6639161aa..43b3e390b 100644 --- a/extensions/github1s/src/router/index.ts +++ b/extensions/github1s/src/router/index.ts @@ -82,14 +82,14 @@ export class Router extends EventEmitter { public async push(path: string) { await this._barrier.wait(); const emptyState = { pathname: '', search: '', hash: '' }; - return this._history!.push({ ...emptyState, ...parsePath(path) }); + return this._history!.push({ ...emptyState, ...parsePath(encodeURI(path)) }); } // replace the url with current history public async replace(path: string) { await this._barrier.wait(); const emptyState = { pathname: '', search: '', hash: '' }; - return this._history!.replace({ ...emptyState, ...parsePath(path) }); + return this._history!.replace({ ...emptyState, ...parsePath(encodeURI(path)) }); } public async resolveParser(): Promise {