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 loading wrong info for non-opened documents #527

Merged
merged 3 commits into from
Jun 26, 2020
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
2 changes: 2 additions & 0 deletions contributors/.all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@
{ "type": "ideas", "link": "issues/402", "text": "#402" },
{ "type": "bug", "link": "issues/458", "text": "#458" },
{ "type": "bug", "link": "issues/487", "text": "#487" },
{ "type": "bug", "link": "issues/515", "text": "#515" },
{ "type": "bug", "link": "issues/516", "text": "#516" },
{ "type": "bug", "link": "issues/517", "text": "#517" },
{ "type": "bug", "link": "issues/519", "text": "#519" },
{ "type": "bug", "link": "issues/520", "text": "#520" }
]
},
Expand Down
2 changes: 1 addition & 1 deletion contributors/2.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A big _thank you_ goes to these wonderful people! (sorted by the Unicode of name
<td align="center"><a href="https://www.mcbbs.net/home.php?mod=space&uid=1834567"><img src="https://www.mcbbs.net/uc_server/avatar.php?uid=1834567&size=middle" width="64px;" alt=""/><br /><sub><b>ChapterII</b></sub></a></td><td align="left"><a href="https://github.com/SPGoding/datapack-language-server/issues/467" target="_blank" title="Bug reports">🐛 #467</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/ChenCMD"><img src="https://avatars2.githubusercontent.com/u/46134240?s=460&u=ca934b86e5189ea9c598a51358571e777e21aa2f&v=4" width="64px;" alt=""/><br /><sub><b>ChenCMD</b></sub></a></td><td align="left"><a href="https://github.com/SPGoding/datapack-language-server/issues/402" target="_blank" title="Ideas, Planning, and Feedback">✨ #402</a><br><a href="https://github.com/SPGoding/datapack-language-server/issues/458" target="_blank" title="Bug reports">🐛 #458</a><br><a href="https://github.com/SPGoding/datapack-language-server/issues/487" target="_blank" title="Bug reports">🐛 #487</a><br><a href="https://github.com/SPGoding/datapack-language-server/issues/516" target="_blank" title="Bug reports">🐛 #516</a><br><a href="https://github.com/SPGoding/datapack-language-server/issues/517" target="_blank" title="Bug reports">🐛 #517</a><br><a href="https://github.com/SPGoding/datapack-language-server/issues/520" target="_blank" title="Bug reports">🐛 #520</a></td>
<td align="center"><a href="https://github.com/ChenCMD"><img src="https://avatars2.githubusercontent.com/u/46134240?s=460&u=ca934b86e5189ea9c598a51358571e777e21aa2f&v=4" width="64px;" alt=""/><br /><sub><b>ChenCMD</b></sub></a></td><td align="left"><a href="https://github.com/SPGoding/datapack-language-server/issues/402" target="_blank" title="Ideas, Planning, and Feedback">✨ #402</a><br><a href="https://github.com/SPGoding/datapack-language-server/issues/458" target="_blank" title="Bug reports">🐛 #458</a><br><a href="https://github.com/SPGoding/datapack-language-server/issues/487" target="_blank" title="Bug reports">🐛 #487</a><br><a href="https://github.com/SPGoding/datapack-language-server/issues/515" target="_blank" title="Bug reports">🐛 #515</a><br><a href="https://github.com/SPGoding/datapack-language-server/issues/516" target="_blank" title="Bug reports">🐛 #516</a><br><a href="https://github.com/SPGoding/datapack-language-server/issues/517" target="_blank" title="Bug reports">🐛 #517</a><br><a href="https://github.com/SPGoding/datapack-language-server/issues/519" target="_blank" title="Bug reports">🐛 #519</a><br><a href="https://github.com/SPGoding/datapack-language-server/issues/520" target="_blank" title="Bug reports">🐛 #520</a></td>
<td align="center"><a href="https://afdian.net/u/da477488928011ea8ea552540025c377"><img src="https://pic1.afdiancdn.com/default/avatar/avatar-purple.png?imageView2/1/w/240/h/240" width="64px;" alt=""/><br /><sub><b>ColorRain_Tree</b></sub></a></td><td align="left"><a href="https://github.com/SPGoding/datapack-language-server/blob/master/CONTRIBUTING.md" target="_blank" title="Financial support">💛 <span style="color:gold;">(#°Д°)</span></a></td>
</tr>
<tr>
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"quote": "a quote (‘'’ or ‘\"’)",
"score-holder": "a score holder",
"server.checking-file": "Checking ‘%0%’",
"server.fixing-workspace": "Fixing all auto-fixable problems in the workspace",
"server.initializing": "Initialize DHP features",
"server.new-version": "The Datapack Language Server has been updated to a newer version: %0%",
"server.regenerating-cache": "Regenerating cache",
Expand Down
2 changes: 0 additions & 2 deletions src/parsers/EntityArgumentParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,6 @@ export class EntityArgumentParser extends ArgumentParser<EntityNode> {
}

export function getNbtdocRegistryId(entity: EntityNode): null | string {
console.log(require('util').inspect(entity, true, null))

if (entity.variable === 'a' || entity.variable === 'p' || entity.variable === 'r') {
return 'minecraft:player'
}
Expand Down
11 changes: 8 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,14 +576,16 @@ connection.onInitialized(() => {
})
break
}
case 'datapack.fixWorkspace':
case 'datapack.fixWorkspace': {
const progress = await connection.window.createWorkDoneProgress()
progress.begin(locale('server.fixing-workspace'))
for (const root of roots) {
const dataPath = path.join(root.fsPath, 'data')
const namespaces = fs.pathExistsSync(dataPath) ? await fs.readdir(dataPath) : []
for (const namespace of namespaces) {
const namespacePath = path.join(dataPath, namespace)
const functionsPath = path.join(namespacePath, 'functions')
walk(root.fsPath, functionsPath, async abs => {
await walk(root.fsPath, functionsPath, async abs => {
try {
const uri = getUri(Uri.file(abs).toString(), uris)
await fixFileCommandHandler({
Expand All @@ -599,8 +601,10 @@ connection.onInitialized(() => {
})
}
}
progress.done()
break
case 'datapack.regenerateCache':
}
case 'datapack.regenerateCache': {
const progress = await connection.window.createWorkDoneProgress()
progress.begin(locale('server.regenerating-cache'))

Expand All @@ -609,6 +613,7 @@ connection.onInitialized(() => {

progress.done()
break
}
default:
throw new Error(`Unknown ‘workspace/executeCommand’ request for ‘${command}’.`)
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/utils/handlers/onDidCloseTextDocument.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ describe('onDidCloseTextDocument() Tests', () => {

onDidCloseTextDocument({ uri, infos })

assert(infos.size === 1)
assert(infos.size === 0)
})
})
5 changes: 0 additions & 5 deletions src/utils/handlers/commands/fixFileCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ export async function fixFileCommandHandler({ uri, roots, infos, cacheFile, read
const info = await getOrCreateInfo(uri, roots, infos, cacheFile, config, readFile, commandTree, vanillaData)
/* istanbul ignore else */
if (info) {
const startTime = new Date().getTime()
const edit = getMergedPreferredEdit(info, uri)
const endTime = new Date().getTime()
console.log(`--------------- Edit for ‘${uri.toString()}’ (${endTime - startTime} ms) ---------------`)
console.log(JSON.stringify(edit, undefined, 4))

if (edit) {
applyEdit(edit)
}
Expand Down
28 changes: 18 additions & 10 deletions src/utils/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,28 @@ export function getInfo(uri: Uri, infos: InfosOfUris): FunctionInfo | undefined
return infos.get(uri)
}

/* istanbul ignore next */
export async function createInfo(uri: Uri, roots: Uri[], infos: InfosOfUris, cacheFile: CacheFile, config: Config, readFile: ReadFileFunction, commandTree?: CommandTree, vanillaData?: VanillaData): Promise<FunctionInfo | undefined> {
try {
const rel = getRel(uri, roots)!
if (isRelIncluded(rel, config)) {
const text = await readFile(uri.fsPath, 'utf8')
await onDidOpenTextDocument({ text, uri, rel, infos, config, cacheFile, version: null, roots, commandTree, vanillaData })
const info = infos.get(uri)
infos.delete(uri)
return info
}
} catch (e) {
console.error('createInfo', e)
}
return undefined
}

export async function getOrCreateInfo(uri: Uri, roots: Uri[], infos: InfosOfUris, cacheFile: CacheFile, config: Config, readFile: ReadFileFunction, commandTree?: CommandTree, vanillaData?: VanillaData): Promise<FunctionInfo | undefined> {
let info = infos.get(uri)

if (!info) {
try {
const rel = getRel(uri, roots)!
if (isRelIncluded(rel, config)) {
const text = await readFile(uri.fsPath, 'utf8')
await onDidOpenTextDocument({ text, uri, rel, infos, config, cacheFile, version: null, roots, commandTree, vanillaData })
info = infos.get(uri)
}
} catch (ignored) {
// Ignored.
}
info = await createInfo(uri, roots, infos, cacheFile, config, readFile, commandTree, vanillaData)
}

return info
Expand Down
4 changes: 2 additions & 2 deletions src/utils/handlers/onDidCloseTextDocument.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InfosOfUris, Uri } from '../../types/handlers'

export function onDidCloseTextDocument({ }: { uri: Uri, infos: InfosOfUris }) {
// infos.delete(uri)
export function onDidCloseTextDocument({ infos, uri }: { uri: Uri, infos: InfosOfUris }) {
infos.delete(uri)
}